use v5.12;
use parent qw(PublicInbox::IPC);
use URI ();
-use PublicInbox::Spawn qw(popen_rd run_die spawn);
+use PublicInbox::Spawn qw(popen_rd run_wait);
use PublicInbox::Admin;
use PublicInbox::LEI;
use PublicInbox::LeiCurl;
warn "W: $edir missing remote.*.url\n";
my $o = { -C => $edir };
$o->{1} = $o->{2} = $lei->{2};
- my $pid = spawn([qw(git config -l)], undef, $o);
- waitpid($pid, 0);
- $lei->child_error($?) if $?;
+ run_wait([qw(git config -l)], undef, $o) and
+ $lei->child_error($?);
}
}
@epochs = grep { !$skip->{$_} } @epochs if $skip;
use Fcntl qw(SEEK_SET);
use PublicInbox::Config;
use PublicInbox::Syscall qw(EPOLLIN);
-use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Spawn qw(run_wait popen_rd);
use PublicInbox::Lock;
use PublicInbox::Eml;
use PublicInbox::Import;
}
my $cmd = $cfg->config_cmd(\%env, \%opt);
push @$cmd, @file_arg, @argv;
- waitpid(spawn($cmd, \%env, \%opt), 0);
- $? == 0 ? 1 : ($err_ok ? undef : fail($self, $?));
+ run_wait($cmd, \%env, \%opt) ? ($err_ok ? undef : fail($self, $?)) : 1;
}
sub lei_daemon_pid { puts shift, $$ }
use strict;
use v5.10.1;
use parent qw(PublicInbox::IPC);
-use PublicInbox::Spawn qw(spawn popen_rd which);
+use PublicInbox::Spawn qw(run_wait popen_rd which);
use PublicInbox::DS;
sub get_git_dir ($$) {
my $cmd = [ 'git', "--git-dir=$gd", 'show', $oid ];
my $rdr = { 1 => $lei->{1}, 2 => $lei->{2} };
- waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
- $lei->child_error($?) if $?;
+ run_wait($cmd, $lei->{env}, $rdr) and $lei->child_error($?);
}
sub do_solve_blob { # via wq_do
require PublicInbox::Eml;
my $buf = do { local $/; <$fh> };
return extract_attach($lei, $blob, \$buf) if close($fh);
- } else {
- $rdr->{1} = $lei->{1};
- waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
}
- my $ce = $?;
- return if $ce == 0;
+ $rdr->{1} = $lei->{1};
+ my $cerr = run_wait($cmd, $lei->{env}, $rdr) or return;
my $lms = $lei->lms;
if (my $bref = $lms ? $lms->local_blob($blob, 1) : undef) {
defined($lei->{-attach_idx}) and
} elsif ($opt->{mail}) {
my $eh = $rdr->{2};
seek($eh, 0, 0);
- return $lei->child_error($ce, do { local $/; <$eh> });
+ return $lei->child_error($cerr, do { local $/; <$eh> });
} # else: fall through to solver below
}
package PublicInbox::LeiMailDiff;
use v5.12;
use parent qw(PublicInbox::IPC PublicInbox::LeiInput PublicInbox::MailDiff);
-use PublicInbox::Spawn qw(spawn which);
+use PublicInbox::Spawn qw(run_wait);
use File::Path ();
require PublicInbox::LeiRediff;
push @$cmd, qw(-- a), "N$self->{nr}";
my $rdr = { -C => "$self->{tmp}" };
@$rdr{1, 2} = @$lei{1, 2};
- my $pid = spawn($cmd, $lei->{env}, $rdr);
- waitpid($pid, 0);
- $lei->child_error($?) if $?; # for git diff --exit-code
+ run_wait($cmd, $lei->{env}, $rdr) and $lei->child_error($?);
File::Path::remove_tree($self->{curdir});
}
use parent qw(PublicInbox::IPC);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use IO::Compress::Gzip qw(gzip $GzipError);
-use PublicInbox::Spawn qw(popen_rd spawn run_die);
+use PublicInbox::Spawn qw(popen_rd spawn run_wait run_die);
use File::Path ();
use File::Temp ();
use File::Spec ();
sub run_reap {
my ($lei, $cmd, $opt) = @_;
$lei->qerr("# @$cmd");
- waitpid(spawn($cmd, undef, $opt), 0) // die "waitpid: $!";
- my $ret = $?;
+ my $ret = run_wait($cmd, undef, $opt);
$? = 0; # don't let it influence normal exit
$ret;
}
my $c = [ @$cmd, '--unset-all', $_ ];
$self->{lei}->qerr("# @$c");
next if $self->{dry_run};
- my $pid = spawn($c, undef, $opt);
- waitpid($pid, 0) // die "waitpid: $!";
+ run_wait($c, undef, $opt);
die "E: @$c \$?=$?" if ($? && ($? >> 8) != 5);
}
use v5.10.1;
use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
use File::Temp 0.19 (); # 0.19 for ->newdir
-use PublicInbox::Spawn qw(spawn which);
+use PublicInbox::Spawn qw(run_wait spawn which);
use PublicInbox::MsgIter qw(msg_part_text);
use PublicInbox::ViewDiff;
use PublicInbox::LeiBlob;
$lei->qerr("# git @$cmd");
push @$cmd, qw(A B);
unshift @$cmd, 'git', "--git-dir=$rw->{git_dir}";
- $pid = spawn($cmd, $lei->{env}, { 2 => $lei->{2}, 1 => $lei->{1} });
- waitpid($pid, 0);
- $lei->child_error($?) if $?; # for git diff --exit-code
+ run_wait($cmd, $lei->{env}, { 2 => $lei->{2}, 1 => $lei->{1} }) and
+ $lei->child_error($?); # for git diff --exit-code
undef;
}
use Fcntl qw(SEEK_SET);
use Time::Local qw(timegm);
use PublicInbox::OverIdx;
-use PublicInbox::Spawn qw(spawn);
+use PublicInbox::Spawn qw(run_wait);
use PublicInbox::Git qw(git_unquote);
use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
use PublicInbox::Address;
return 0 unless $git->check($cur);
my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
qw(merge-base --is-ancestor), $cur, $tip ];
- my $pid = spawn($cmd);
- waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
- $? == 0;
+ run_wait($cmd) == 0;
}
sub need_update ($$$$) {
# Default spam filter class for wrapping spamc(1)
package PublicInbox::Spamcheck::Spamc;
use v5.12;
-use PublicInbox::Spawn qw(popen_rd spawn);
+use PublicInbox::Spawn qw(popen_rd run_wait);
use IO::Handle;
use Fcntl qw(SEEK_SET);
$rdr->{0} = _msg_to_fh($self, $msg);
$rdr->{1} ||= $self->_devnull;
$rdr->{2} ||= $self->_devnull;
- my $pid = spawn($self->{$field}, undef, $rdr);
- waitpid($pid, 0);
- !$?;
+ 0 == run_wait($self->{$field}, undef, $rdr);
}
sub _devnull {
use Symbol qw(gensym);
use Fcntl qw(LOCK_EX SEEK_SET);
use IO::Handle ();
+use Carp qw(croak);
use PublicInbox::ProcessPipe;
-our @EXPORT_OK = qw(which spawn popen_rd run_die);
+our @EXPORT_OK = qw(which spawn popen_rd run_die run_wait);
our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA);
BEGIN {
$s;
}
+sub run_wait ($;$$) {
+ my ($cmd, $env, $opt) = @_;
+ waitpid(spawn($cmd, $env, $opt), 0);
+ $?
+}
+
sub run_die ($;$$) {
my ($cmd, $env, $rdr) = @_;
- my $pid = spawn($cmd, $env, $rdr);
- waitpid($pid, 0) == $pid or die "@$cmd did not finish";
- $? == 0 or die "@$cmd failed: \$?=$?\n";
+ run_wait($cmd, $env, $rdr) and croak "E: @$cmd failed: \$?=$?";
}
1;
$cmd->[0] = File::Spec->rel2abs($cmd->[0]);
$spawn_opt->{'-C'} = $d;
}
- my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
- if (defined $pid) {
- my $r = waitpid($pid, 0) // die "waitpid: $!";
- $r == $pid or die "waitpid: expected $pid, got $r";
- }
+ PublicInbox::Spawn::run_wait($cmd, $env, $spawn_opt);
} else { # localize and run everything in the same process:
# note: "local *STDIN = *STDIN;" and so forth did not work in
# old versions of perl