From: Gurusamy Sarathy Date: Sat, 19 Feb 2000 07:42:12 +0000 (+0000) Subject: set close-on-exec flag on sockets too, like we do for files X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8d2a6795a8433e9623ccf677a19bf470170549e9;p=p5sagit%2Fp5-mst-13.2.git set close-on-exec flag on sockets too, like we do for files and pipes p4raw-id: //depot/perl@5137 --- diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 9e0d0c3..eb44fc4 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -81,13 +81,15 @@ Using the C operator on a readonly value (such as $1) has the same effect as assigning C to the readonly value--it throws an exception. -=item Close-on-exec bit may be set on pipe() handles +=item Close-on-exec bit may be set on pipe and socket handles On systems that support a close-on-exec flag on filehandles, the -flag will be set for any handles created by pipe(), if that is -warranted by the value of $^F that may be in effect. Earlier -versions neglected to set the flag for handles created with -pipe(). See L and L. +flag will be set for any handles created by pipe(), socketpair(), +socket(), and accept(), if that is warranted by the value of $^F +that may be in effect. Earlier versions neglected to set the flag +for handles created with these operators. See L, +L, L, L, +and L. =item Writing C<"$$1"> to mean C<"${$}1"> is unsupported diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index e8f4fe0..39798fd 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -376,6 +376,10 @@ Accepts an incoming socket connect, just as the accept(2) system call does. Returns the packed address if it succeeded, false otherwise. See the example in L. +On systems that support a close-on-exec flag on files, the flag will +be set for the newly opened file descriptor, as determined by the +value of $^F. See L. + =item alarm SECONDS =item alarm @@ -4006,6 +4010,10 @@ the system call of the same name. You should C first to get the proper definitions imported. See the examples in L. +On systems that support a close-on-exec flag on files, the flag will +be set for the newly opened file descriptor, as determined by the +value of $^F. See L. + =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL Creates an unnamed pair of sockets in the specified domain, of the @@ -4013,6 +4021,10 @@ specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as for the system call of the same name. If unimplemented, yields a fatal error. Returns true if successful. +On systems that support a close-on-exec flag on files, the flag will +be set for the newly opened file descriptors, as determined by the value +of $^F. See L. + Some systems defined C in terms of C, in which a call to C is essentially: diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 7c499bc..17b570f 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -715,7 +715,8 @@ descriptors are not. Also, during an open(), system file descriptors are preserved even if the open() fails. (Ordinary file descriptors are closed before the open() is attempted.) The close-on-exec status of a file descriptor will be decided according to the value of -C<$^F> when the open() or pipe() was called, not the time of the exec(). +C<$^F> when the corresponding file, pipe, or socket was opened, not the +time of the exec(). =item $^H diff --git a/pp_sys.c b/pp_sys.c index a9292a1..18edf7a 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2042,6 +2042,9 @@ PP(pp_socket) if (!IoIFP(io) && !IoOFP(io)) PerlLIO_close(fd); RETPUSHUNDEF; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd, F_SETFD, fd > PL_maxsysfd); /* ensure close-on-exec */ +#endif RETPUSHYES; #else @@ -2092,6 +2095,10 @@ PP(pp_sockpair) if (!IoIFP(io2) && !IoOFP(io2)) PerlLIO_close(fd[1]); RETPUSHUNDEF; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd[0],F_SETFD,fd[0] > PL_maxsysfd); /* ensure close-on-exec */ + fcntl(fd[1],F_SETFD,fd[1] > PL_maxsysfd); /* ensure close-on-exec */ +#endif RETPUSHYES; #else @@ -2254,6 +2261,9 @@ PP(pp_accept) if (!IoIFP(nstio) && !IoOFP(nstio)) PerlLIO_close(fd); goto badexit; } +#if defined(HAS_FCNTL) && defined(F_SETFD) + fcntl(fd, F_SETFD, fd > PL_maxsysfd); /* ensure close-on-exec */ +#endif PUSHp((char *)&saddr, len); RETURN;