pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-netif/+/34072 )
Change subject: stream_srv: call setsockopt(SO_NOSIGPIPE) also in srv sockets
......................................................................
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
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 38 insertions(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
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 @@
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 @@
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 @@
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 @@
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;
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-netif/+/34072
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I867d8e244e473679abb7e7e7a9b531eeed046436
Gerrit-Change-Number: 34072
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged