]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SpawnPP.pm
Merge remote-tracking branch 'origin/purge'
[public-inbox.git] / lib / PublicInbox / SpawnPP.pm
index 36223e8132eefa30c380bf1b07fef42bbf40628b..743db224ad0b8609ce80927255c0c61f8f301baf 100644 (file)
@@ -1,5 +1,8 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Pure-Perl implementation of "spawn".  This can't take advantage
+# of vfork, so no speedups under Linux for spawning from large processes.
 package PublicInbox::SpawnPP;
 use strict;
 use warnings;
@@ -12,7 +15,12 @@ sub public_inbox_fork_exec ($$$$$$) {
        my $set = POSIX::SigSet->new();
        $set->fillset or die "fillset failed: $!";
        sigprocmask(SIG_SETMASK, $set, $old) or die "can't block signals: $!";
+       my $syserr;
        my $pid = fork;
+       unless (defined $pid) { # compat with Inline::C version
+               $syserr = $!;
+               $pid = -1;
+       }
        if ($pid == 0) {
                if ($in != 0) {
                        dup2($in, 0) or die "dup2 failed for stdin: $!";
@@ -34,6 +42,7 @@ sub public_inbox_fork_exec ($$$$$$) {
                }
        }
        sigprocmask(SIG_SETMASK, $old) or die "can't unblock signals: $!";
+       $! = $syserr;
        $pid;
 }