]> git.sesse.net Git - cubemap/commitdiff
Fix various close-on-exec bugs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 6 May 2021 17:26:38 +0000 (19:26 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 6 May 2021 17:26:38 +0000 (19:26 +0200)
acceptor.cpp
client.cpp
httpinput.cpp
serverpool.cpp
stream.cpp
udpinput.cpp

index 2fef9148d9a4a93114986a11eadbcf590dbcb463..31901dd8406c97c39d97dc9b3310dedb4f37a18e 100644 (file)
@@ -104,7 +104,7 @@ Acceptor::Acceptor(const AcceptorProto &serialized)
 {
        // 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(server_sock, F_SETFD, 1);
+       fcntl(server_sock, F_SETFD, O_CLOEXEC);
 }
 
 AcceptorProto Acceptor::serialize() const
index 26806d6fdcf53d88a2ae758adbbbce7c10e1b214..5d5c179be0e6df019930fb2924cf22be2e7bcab1 100644 (file)
@@ -72,7 +72,7 @@ Client::Client(const ClientProto &serialized, const vector<shared_ptr<const stri
 {
        // 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);
+       fcntl(sock, F_SETFD, O_CLOEXEC);
 
        if (stream != nullptr) {
                if (setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, &stream->pacing_rate, sizeof(stream->pacing_rate)) == -1) {
index 3a6b3c8af561afba6ca00a23bcb5d621ed79cb17..8d443c7d069214369af7020d258555aeeb6e3379 100644 (file)
@@ -80,7 +80,7 @@ HTTPInput::HTTPInput(const InputProto &serialized)
 {
        // 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);
+       fcntl(sock, F_SETFD, O_CLOEXEC);
 
        pending_data.resize(serialized.pending_data().size());
        memcpy(&pending_data[0], serialized.pending_data().data(), serialized.pending_data().size());
index e9fea12944d13455ee7315685a32c7f2ed6fc9ae..c7ff10cf2866057e3ddc7a996a6d999da967720e 100644 (file)
@@ -1,4 +1,5 @@
 #include <assert.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <sys/types.h>
 
index 3ee1a434d2e6fe6c3cc73fcc84d89d860efd0f05..4e5ca24cceab8870dfdfa00e66b161aecc61f729 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <math.h>
@@ -67,6 +68,9 @@ Stream::Stream(const StreamProto &serialized, int data_fd)
                exit(1);
        }
 
+       // Set the close-on-exec parameter back on the backlog fd.
+       fcntl(data_fd, F_SETFD, O_CLOEXEC);
+
        for (ssize_t point : serialized.suitable_starting_point()) {
                if (point == -1) {
                        // Can happen when upgrading from before 1.1.3,
@@ -103,6 +107,10 @@ StreamProto Stream::serialize()
        serialized.set_first_fragment_index(first_fragment_index);
        serialized.set_discontinuity_counter(discontinuity_counter);
 
+       // Unset the close-on-exec flag for the backlog fd.
+       // (This can't leak into a child, since there's only one thread left.)
+       fcntl(data_fd, F_SETFD, 0);
+
        serialized.set_url(url);
        data_fd = -1;
        return serialized;
index ecd099a529913250b99531f4427fa6c56ec6d91f..873b0b952911a226d8f08255f80e2d092e163801 100644 (file)
@@ -123,7 +123,7 @@ UDPInput::UDPInput(const InputProto &serialized)
 {
        // 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);
+       fcntl(sock, F_SETFD, O_CLOEXEC);
 
        // Should be verified by the caller.
        string protocol;