This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mask off SOCK_CLOEXEC in socketpair() emulation
authorZefram <zefram@fysh.org>
Fri, 22 Dec 2017 15:23:11 +0000 (15:23 +0000)
committerZefram <zefram@fysh.org>
Fri, 22 Dec 2017 16:37:47 +0000 (16:37 +0000)
In the unlikely situation that we have SOCK_CLOEXEC but are emulating
socketpair(), having the bit set could confuse the emulation.  It's not
worth actually implementing SOCK_CLOEXEC logic for this situation, so
just mask it off.  The higher-level logic of PerlSock_socketpair_cloexec()
will handle the bit being ineffective.

util.c

diff --git a/util.c b/util.c
index 41aadca..0fc7af6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4176,6 +4176,10 @@ Perl_my_socketpair (int family, int type, int protocol, int fd[2]) {
        return -1;
     }
 
+#ifdef SOCK_CLOEXEC
+    type &= ~SOCK_CLOEXEC;
+#endif
+
 #ifdef EMULATE_SOCKETPAIR_UDP
     if (type == SOCK_DGRAM)
        return S_socketpair_udp(fd);