This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move the close-on-exec logic to one place, at the end of S_open_script().
authorNicholas Clark <nick@ccl4.org>
Thu, 23 Feb 2012 16:45:26 +0000 (17:45 +0100)
committerNicholas Clark <nick@ccl4.org>
Mon, 27 Feb 2012 10:31:48 +0000 (11:31 +0100)
Now that the logic for stdin is implemented as an early return of NULL from
S_open_script(), in all cases that reach the end of S_open_script(), rsfp
is non-NULL, and a file handle that we wish to set to close on exec.

perl.c

diff --git a/perl.c b/perl.c
index 83b5cde..3610780 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3672,11 +3672,6 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
        scriptname = (char *)"";
     if (fdscript >= 0) {
        rsfp = PerlIO_fdopen(fdscript,PERL_SCRIPT_MODE);
-#       if defined(HAS_FCNTL) && defined(F_SETFD)
-           if (rsfp)
-                /* ensure close-on-exec */
-               fcntl(PerlIO_fileno(rsfp),F_SETFD,1);
-#       endif
     }
     else if (!*scriptname) {
        forbid_setid(0, *suidscript);
@@ -3724,11 +3719,6 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
        }
        scriptname = BIT_BUCKET;
 #endif
-#       if defined(HAS_FCNTL) && defined(F_SETFD)
-           if (rsfp)
-                /* ensure close-on-exec */
-               fcntl(PerlIO_fileno(rsfp),F_SETFD,1);
-#       endif
     }
     if (!rsfp) {
        /* PSz 16 Sep 03  Keep neat error message */
@@ -3738,6 +3728,10 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
            Perl_croak(aTHX_ "Can't open perl script \"%s\": %s\n",
                    CopFILE(PL_curcop), Strerror(errno));
     }
+#if defined(HAS_FCNTL) && defined(F_SETFD)
+    /* ensure close-on-exec */
+    fcntl(PerlIO_fileno(rsfp), F_SETFD, 1);
+#endif
     return rsfp;
 }