chiark / gitweb /
prefork-interp: Except fd 2 from call_fds closing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Aug 2022 21:33:12 +0000 (22:33 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 20:21:10 +0000 (21:21 +0100)
For the first run, stderr is the inherited fd

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
perl/Prefork.pm

index 3eb9a27e2e466b64ae12db6988121297980a1994..4fbc2b58ad85f9cf613136e3471d60b62e4e8c90 100644 (file)
@@ -36,8 +36,7 @@ sub become_monitor () {
     open ::STDIN , "<& $call_fds[0]" or fail_log("dup for fd0");
     open ::STDOUT, ">& $call_fds[1]" or fail_log("dup for fd1");
     open ::STDERR, ">& $call_fds[2]" or fail_log("dup for fd2");
-    POSIX::close($_) foreach @call_fds;
-    close CALL;
+    close_call_fds();
     return;
   }
 
@@ -49,6 +48,14 @@ sub become_monitor () {
   _exit(0);
 }
 
+sub close_call_fds () {
+  foreach (@call_fds) {
+    next if $_ <= 2;
+    POSIX::close($_);
+  }
+  close CALL;
+}
+
 sub protocol_write ($) {
   my ($d) = @_;
   return if (print CALL $d and flush CALL);
@@ -160,8 +167,7 @@ sub initialisation_complete {
   open STDERR, ">&NULL" or fail_log("dup null onto stderr: $!");
   close NULL;
 
-  POSIX::close($_) foreach @call_fds;
-  close CALL;
+  close_call_fds();
 
   my $flags = fcntl(LISTEN, F_GETFL, 0)
     or fail_log("F_GETFL listen socket: $!");