]> git.meshlink.io Git - meshlink/commitdiff
Set NOSIGPIPE on all sockets.
authorGuus Sliepen <guus@meshlink.io>
Sat, 13 Jun 2020 19:39:39 +0000 (21:39 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sat, 13 Jun 2020 19:39:39 +0000 (21:39 +0200)
MacOS can raise a SIGPIPE when a local socket gets disconnected.

src/meshlink.c
src/net_socket.c
src/utcp-test.c

index d3cf36ad5e5801fdaae0d8591520841cea230385..a5d8d43121b025cf1c7b5993c93b4f464d31e675 100644 (file)
@@ -268,6 +268,11 @@ char *meshlink_get_external_address_for_family(meshlink_handle_t *mesh, int fami
 
                int s = socket_in_netns(aip->ai_family, aip->ai_socktype, aip->ai_protocol, mesh->netns);
 
+#ifdef SO_NOSIGPIPE
+               int nosigpipe = 1;
+               setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
                if(s >= 0) {
                        set_timeout(s, 5000);
 
@@ -2905,6 +2910,11 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
                                        continue;
                                }
 
+#ifdef SO_NOSIGPIPE
+                               int nosigpipe = 1;
+                               setsockopt(state.sock, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
                                set_timeout(state.sock, 5000);
 
                                if(connect(state.sock, aip->ai_addr, aip->ai_addrlen)) {
index 51a79c1d4cf54569aa74bdb37f34c297ea306ef0..5464b95f8071ca57ee479270e32ffcf3c23e0b25 100644 (file)
@@ -71,6 +71,11 @@ static void configure_tcp(connection_t *c) {
        int lowdelay = IPTOS_LOWDELAY;
        setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&lowdelay, sizeof(lowdelay));
 #endif
+
+#if defined(SO_NOSIGPIPE)
+       int nosigpipe = 1;
+       setsockopt(c->socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&nosigpipe, sizeof(nosigpipe));
+#endif
 }
 
 static void retry_outgoing_handler(event_loop_t *loop, void *data) {
index d78c4b860073c7a0ef0363448a68cad3590c7721..564bfba8618472fdcffe646d9dcb54efeb937ce4 100644 (file)
@@ -270,6 +270,11 @@ int main(int argc, char *argv[]) {
                        return 1;
                }
        } else {
+#ifdef SO_NOSIGPIPE
+               int nosigpipe = 1;
+               setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
                if(connect(s, ai->ai_addr, ai->ai_addrlen)) {
                        debug("Could not connect: %s\n", strerror(errno));
                        return 1;