my ($in, $out);
my @cmd = (qw/git config/, "--file=$file", '-l');
my $cmd = join(' ', @cmd);
- my $fh = popen_rd(\@cmd);
+ my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
my %rv;
local $/ = "\n";
foreach my $line (<$fh>) {
my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
- $self->{$pid} = spawn(\@cmd, undef, $redir);
+ my $p = spawn(\@cmd, undef, $redir);
+ defined $p or fail($self, "spawn failed: $!");
+ $self->{$pid} = $p;
$out_w->autoflush(1);
$self->{$out} = $out_w;
$self->{$in} = $in_r;
sub qx {
my ($self, @cmd) = @_;
my $fh = $self->popen(@cmd);
+ defined $fh or return;
local $/ = "\n";
return <$fh> if wantarray;
local $/;
my ($self, $cb) = @_;
my $err;
($self->{rpipe}, $self->{pid}) = popen_rd(@{$self->{args}});
- if ($self->{pid}) {
+ if (defined $self->{pid}) {
$running++;
} else {
$self->{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);
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;
}
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 {
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;
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: $!";
}
}
sigprocmask(SIG_SETMASK, $old) or die "can't unblock signals: $!";
+ $! = $syserr;
$pid;
}
my ($in, $out) = @_;
my $rdr = { 0 => fileno($in) };
my ($fh, $pid) = popen_rd([qw/spamc -E --headers/], undef, $rdr);
+ defined $pid or die "failed to popen_rd spamc: $!\n";
my $r;
do {
$r = sysread($fh, $$out, 65536, length($$out));