]> git.sesse.net Git - cubemap/blobdiff - udpinput.cpp
Set close-on-exec on all file descriptors we open.
[cubemap] / udpinput.cpp
index 4b421a3e4fe90c91732a7a24c53adc476175fd7d..ecd099a529913250b99531f4427fa6c56ec6d91f 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <poll.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -120,6 +121,10 @@ UDPInput::UDPInput(const InputProto &serialized)
        : url(serialized.url()),
          sock(serialized.sock())
 {
+       // Set back the close-on-exec flag for the socket.
+       // (This can't leak into a child, since we haven't been started yet.)
+       fcntl(sock, F_SETFD, 1);
+
        // Should be verified by the caller.
        string protocol;
        bool ok = parse_url(url, &protocol, &user, &host, &port, &path);
@@ -139,6 +144,10 @@ UDPInput::UDPInput(const InputProto &serialized)
 
 InputProto UDPInput::serialize() const
 {
+       // Unset the close-on-exec flag for the socket.
+       // (This can't leak into a child, since there's only one thread left.)
+       fcntl(sock, F_SETFD, 0);
+
        InputProto serialized;
        serialized.set_url(url);
        serialized.set_sock(sock);