summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-02-23 17:45:26 +0100
committerNicholas Clark <nick@ccl4.org>2012-02-27 11:31:48 +0100
commita7c8193001a8197325b9fbb189ee567db3ca6219 (patch)
tree0793f1993533704acb03a0d45f82b62337de2fe7
parentc0b3891a0ac343a3eaf6b03bd8fd33242e3280aa (diff)
downloadperl-a7c8193001a8197325b9fbb189ee567db3ca6219.tar.gz
Move the close-on-exec logic to one place, at the end of S_open_script().
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.
-rw-r--r--perl.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/perl.c b/perl.c
index 83b5cdeabf..3610780ca3 100644
--- 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;
}