about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-07 23:05:21 -1000
committerEric Wong <e@80x24.org>2021-02-08 22:07:50 +0000
commit29e530f1c0694107ad25881a2c693c30783f85f1 (patch)
tree5855eabccbdd1a8f5c2050ed52d49713f2be55df /lib
parentecd4e2e20f1af200697e54c2a322a459cdf4c5fc (diff)
downloadpublic-inbox-29e530f1c0694107ad25881a2c693c30783f85f1.tar.gz
This matches the Inline::C version, and lets us test
argv overflow with $search->query_argv_to_string;
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/SpawnPP.pm23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index 2c5edef6..6d7e2c34 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -16,13 +16,19 @@ sub pi_fork_exec ($$$$$$$) {
         $set->fillset or die "fillset failed: $!";
         sigprocmask(SIG_SETMASK, $set, $old) or die "can't block signals: $!";
         my $syserr;
+        pipe(my ($r, $w));
         my $pid = fork;
         unless (defined $pid) { # compat with Inline::C version
                 $syserr = $!;
                 $pid = -1;
         }
         if ($pid == 0) {
-                $SIG{__DIE__} = sub { warn @_; _exit 1 };
+                close $r;
+                $SIG{__DIE__} = sub {
+                        warn(@_);
+                        syswrite($w, my $num = $! + 0);
+                        _exit(1);
+                };
                 for my $child_fd (0..$#$redir) {
                         my $parent_fd = $redir->[$child_fd];
                         next if $parent_fd == $child_fd;
@@ -32,7 +38,9 @@ sub pi_fork_exec ($$$$$$$) {
                 if ($pgid >= 0 && !defined(setpgid(0, $pgid))) {
                         die "setpgid(0, $pgid): $!";
                 }
-                $SIG{$_} = 'DEFAULT' for keys %SIG;
+                for (keys %SIG) {
+                        $SIG{$_} = 'DEFAULT' if substr($_, 0, 1) ne '_';
+                }
                 if ($cd ne '') {
                         chdir $cd or die "chdir $cd: $!";
                 }
@@ -49,11 +57,18 @@ sub pi_fork_exec ($$$$$$$) {
                 } else {
                         %ENV = map { split(/=/, $_, 2) } @$env;
                 }
-                exec @$cmd;
+                undef $r;
+                exec { $f } @$cmd;
                 die "exec @$cmd failed: $!";
         }
+        close $w;
         sigprocmask(SIG_SETMASK, $old) or die "can't unblock signals: $!";
-        $! = $syserr;
+        if (my $cerrnum = do { local $/, <$r> }) {
+                $pid = -1;
+                $! = $cerrnum;
+        } else {
+                $! = $syserr;
+        }
         $pid;
 }