diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-08-04 13:56:08 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-08-07 19:16:24 +0200 |
commit | 7e68ac2c04fac4c32b3f5da71ed227654ceffe05 (patch) | |
tree | 9ce14bb3103919e65c6f2a3bb2c17b303bde2627 | |
parent | f42d4c3bb36034189a55200780d929479ab5e8a8 (diff) |
stream_srv: call setsockopt(SO_NOSIGPIPE) also in srv sockets
Commit 5b0ad8bd851e4ce888b386be68c1821e4f2ca301 added call to
setsockopt(SO_NOSIGPIPE) in order to avoid SIGPIPE being signalled on
platforms not supporting send() flag MSG_NOSIGNAL (macOS, FreeBSD
etc...).
While it may be a topic to discuss whether we support those platorms or
not, the fact that we call an extra setsockopt() during socket creation
doesn't hurt much, and for sure we want to have the same behavior in
client and server.
Hence, this commit adds the same behavior pesent in srv sockets to cli
ones.
Change-Id: I867d8e244e473679abb7e7e7a9b531eeed046436
-rw-r--r-- | src/stream_cli.c | 2 | ||||
-rw-r--r-- | src/stream_srv.c | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/stream_cli.c b/src/stream_cli.c index 72a86c3..9845f14 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -308,7 +308,7 @@ static int _setsockopt_nosigpipe(struct osmo_stream_cli *cli) int val = 1; ret = setsockopt(osmo_stream_cli_fd(cli), SOL_SOCKET, SO_NOSIGPIPE, (void *)&val, sizeof(val)); if (ret < 0) - LOGSCLI(cli, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno)); + LOGSCLI(cli, LOGL_ERROR, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno)); return ret; #else return 0; diff --git a/src/stream_srv.c b/src/stream_srv.c index 1ef2cc4..6898ef4 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -97,6 +97,20 @@ struct osmo_stream_srv_link { int flags; }; +static int _setsockopt_nosigpipe(struct osmo_stream_srv_link *link, int new_fd) +{ +#ifdef SO_NOSIGPIPE + int ret; + int val = 1; + ret = setsockopt(new_fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&val, sizeof(val)); + if (ret < 0) + LOGSLNK(link, LOGL_ERROR, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno)); + return ret; +#else + return 0; +#endif +} + static int osmo_stream_srv_link_ofd_cb(struct osmo_fd *ofd, unsigned int what) { int ret; @@ -117,6 +131,7 @@ static int osmo_stream_srv_link_ofd_cb(struct osmo_fd *ofd, unsigned int what) case AF_UNIX: LOGSLNK(link, LOGL_DEBUG, "accept()ed new link on fd %d\n", sock_fd); + _setsockopt_nosigpipe(link, sock_fd); break; case AF_INET6: case AF_INET: @@ -124,6 +139,7 @@ static int osmo_stream_srv_link_ofd_cb(struct osmo_fd *ofd, unsigned int what) osmo_sockaddr_to_str(&osa)); if (link->proto == IPPROTO_SCTP) { + _setsockopt_nosigpipe(link, sock_fd); ret = stream_sctp_sock_activate_events(sock_fd); if (ret < 0) goto error_close_socket; |