]> git.tdb.fi Git - libs/net.git/commitdiff
Mark sockets as close-on-exec upon creation on Linux
authorMikko Rasa <tdb@tdb.fi>
Sun, 11 Dec 2022 15:59:16 +0000 (17:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 11 Dec 2022 16:26:44 +0000 (18:26 +0200)
source/net/socket.cpp

index 84db6375c5c7b96c0db0a211e6ff201f527a0c49..2a1a71c0a4b3aa404b616f09a7be6e1799660c27 100644 (file)
@@ -29,8 +29,13 @@ Socket::Socket(Family af, int type, int proto):
 {
        mode = IO::M_RDWR;
 
-       // TODO use SOCK_CLOEXEC on Linux
+#ifdef __linux__
+       type |= SOCK_CLOEXEC;
+#endif
        priv->handle = socket(family_to_sys(af), type, proto);
+#ifndef __linux__
+       set_inherit(false);
+#endif
 
        platform_init();
 }