This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
factor out remaining fcntl F_SETFD calls
authorZefram <zefram@fysh.org>
Tue, 19 Dec 2017 17:11:25 +0000 (17:11 +0000)
committerZefram <zefram@fysh.org>
Fri, 22 Dec 2017 16:13:26 +0000 (16:13 +0000)
doio.c
perl.c
toke.c

diff --git a/doio.c b/doio.c
index 160adc5..56615cd 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1014,12 +1014,10 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname,
        PerlIO_clearerr(fp);
        fd = PerlIO_fileno(fp);
     }
-#if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
-    if (fd >= 0 && fd > PL_maxsysfd && fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
-        PerlLIO_close(fd);
-        goto say_false;
+    if (fd >= 0) {
+       setfd_cloexec(fd);
+       setfd_inhexec_for_sysfd(fd);
     }
-#endif
     IoIFP(io) = fp;
 
     IoFLAGS(io) &= ~IOf_NOLINE;
diff --git a/perl.c b/perl.c
index dabe45d..0c05c9a 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -4063,15 +4063,8 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
                    CopFILE(PL_curcop), Strerror(errno));
     }
     fd = PerlIO_fileno(rsfp);
-#if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
-    if (fd >= 0) {
-        /* ensure close-on-exec */
-        if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
-            Perl_croak(aTHX_ "Can't open perl script \"%s\": %s\n",
-                       CopFILE(PL_curcop), Strerror(errno));
-        }
-    }
-#endif
+    if (fd >= 0)
+       setfd_cloexec(fd);
 
     if (fd < 0 ||
         (PerlLIO_fstat(fd, &tmpstatbuf) >= 0
diff --git a/toke.c b/toke.c
index 7f822d1..eea1a79 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -7668,14 +7668,11 @@ Perl_yylex(pTHX)
                if (!GvIO(gv))
                    GvIOp(gv) = newIO();
                IoIFP(GvIOp(gv)) = PL_rsfp;
-#if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
                {
                    const int fd = PerlIO_fileno(PL_rsfp);
-                    if (fd >= 3) {
-                        fcntl(fd,F_SETFD, FD_CLOEXEC);
-                    }
+                    if (fd >= 3)
+                       setfd_cloexec(fd);
                }
-#endif
                /* Mark this internal pseudo-handle as clean */
                IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
                if ((PerlIO*)PL_rsfp == PerlIO_stdin())