X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSpawn.pm;h=91a3c123e736635a833fcc6fefa810616349fb9c;hb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;hp=66dce3353e3bd872fad51838a53200bf94f50632;hpb=3f779258173530ca88f31e1dc5332f951d2c44cd;p=public-inbox.git diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 66dce335..91a3c123 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2016 all contributors +# Copyright (C) 2016-2018 all contributors # License: AGPL-3.0+ # # This allows vfork to be used for spawning subprocesses if @@ -84,7 +84,7 @@ int public_inbox_fork_exec(int in, int out, int err, char **argv, **envp; I32 max; sigset_t set, old; - int ret; + int ret, errnum; argv = AV_ALLOCA(cmd, max); av2c_copy(argv, cmd, max); @@ -104,14 +104,18 @@ int public_inbox_fork_exec(int in, int out, int err, REDIR(out, 1); REDIR(err, 2); for (sig = 1; sig < NSIG; sig++) - signal(sig, SIG_DFL); /* ignore errorrs on signals */ - ret = sigprocmask(SIG_SETMASK, &old, NULL); - if (ret != 0) xerr("sigprocmask failed in vfork child"); + signal(sig, SIG_DFL); /* ignore errors on signals */ + /* + * don't bother unblocking, we don't want signals + * to the group taking out a subprocess + */ execve(filename, argv, envp); xerr("execve failed"); } + errnum = errno; ret = sigprocmask(SIG_SETMASK, &old, NULL); assert(ret == 0 && "BUG calling sigprocmask to restore"); + errno = errnum; return (int)pid; } @@ -178,7 +182,8 @@ sub spawn ($;$$) { my $in = $opts->{0} || 0; my $out = $opts->{1} || 1; my $err = $opts->{2} || 2; - public_inbox_fork_exec($in, $out, $err, $f, $cmd, \@env); + my $pid = public_inbox_fork_exec($in, $out, $err, $f, $cmd, \@env); + $pid < 0 ? undef : $pid; } sub popen_rd { @@ -189,6 +194,7 @@ sub popen_rd { IO::Handle::blocking($r, $blocking) if defined $blocking; $opts->{1} = fileno($w); my $pid = spawn($cmd, $env, $opts); + return unless defined $pid; return ($r, $pid) if wantarray; my $ret = gensym; tie *$ret, 'PublicInbox::ProcessPipe', $pid, $r;