]> diplodocus.org Git - nmh/commitdiff
Set the close-on-exec flag for sockets
authorKen Hornstein <kenh@pobox.com>
Tue, 23 Apr 2019 01:42:14 +0000 (21:42 -0400)
committerKen Hornstein <kenh@pobox.com>
Tue, 23 Apr 2019 01:42:14 +0000 (21:42 -0400)
Since we no longer use closefds(), start cleaning up stray descriptors.
Start by making sure that any network sockets we create have the
close-on-exec flag set on them.

sbr/client.c

index 572f8ee0adecf046c00ce3b52f64038c1fc98c5e..2bed9052b953502d5eb7822dae01228352e7698a 100644 (file)
@@ -9,6 +9,7 @@
 #include "client.h"
 #include "h/mts.h"
 #include "h/utils.h"
+#include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
@@ -71,7 +72,15 @@ client (char *server, char *service, char *response, int len_response,
        }
 
        if (connect(sd, ai->ai_addr, ai->ai_addrlen) == 0) {
+           int flags;
+
            freeaddrinfo(res);
+
+           flags = fcntl(sd, F_GETFD, 0);
+
+           if (flags != -1)
+               fcntl(sd, F_SETFD, flags | FD_CLOEXEC);
+
            return sd;
        }