]> Sergey Matveev's repositories - public-inbox.git/commitdiff
spawn (and thus popen_rd) die on failure
authorEric Wong <e@yhbt.net>
Fri, 10 Jan 2020 09:14:19 +0000 (09:14 +0000)
committerEric Wong <e@yhbt.net>
Sat, 11 Jan 2020 06:32:08 +0000 (06:32 +0000)
Most spawn and popen_rd callers die on failure to spawn,
anyways, and some are missing checks entirely.  This saves
us a bunch of verbose error-checking code in callers.

This also makes popen_rd more consistent, since it already
dies on pipe creation failures.

lib/PublicInbox/Config.pm
lib/PublicInbox/Git.pm
lib/PublicInbox/Import.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/Spamcheck/Spamc.pm
lib/PublicInbox/Spawn.pm
lib/PublicInbox/TestCommon.pm
lib/PublicInbox/V2Writable.pm
lib/PublicInbox/WatchMaildir.pm
lib/PublicInbox/WwwListing.pm
t/check-www-inbox.perl

index cc8c1eafb804e12f8c2c34d53740b24479ed4f11..56d146c2292f4cf83bc53936ffe4dffcb41e1dd4 100644 (file)
@@ -158,7 +158,7 @@ sub git_config_dump {
        return {} unless -e $file;
        my @cmd = (qw/git config -z -l/, "--file=$file");
        my $cmd = join(' ', @cmd);
-       my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
+       my $fh = popen_rd(\@cmd);
        my $rv = config_fh_parse($fh, "\0", "\n");
        close $fh or die "failed to close ($cmd) pipe: $?";
        $rv;
index f3b7a0a0ef80f2437931ba4b464638f2f1aff060..8ee04e17b511ca1b7c470aa05ea7ce30f26ac033 100644 (file)
@@ -122,7 +122,6 @@ sub _bidi_pipe {
                $redir->{2} = $fh;
        }
        my $p = spawn(\@cmd, undef, $redir);
-       defined $p or fail($self, "spawn failed: $!");
        $self->{$pid} = $p;
        $out_w->autoflush(1);
        $self->{$out} = $out_w;
@@ -256,7 +255,6 @@ sub popen {
 sub qx {
        my ($self, @cmd) = @_;
        my $fh = $self->popen(@cmd);
-       defined $fh or return;
        local $/ = "\n";
        return <$fh> if wantarray;
        local $/;
@@ -347,7 +345,6 @@ sub modified ($) {
        my ($self) = @_;
        my $modified = 0;
        my $fh = popen($self, qw(rev-parse --branches));
-       defined $fh or return $modified;
        cat_async_begin($self);
        local $/ = "\n";
        foreach my $oid (<$fh>) {
index 572e9bb9899fc464671510dc26275d51d6b7ce8c..6ac43d372d38d2e99d55bfb101f80e00c56333b6 100644 (file)
@@ -68,7 +68,6 @@ sub gfi_start {
                        --quiet --done --date-format=raw));
        my $rdr = { 0 => $out_r, 1 => $in_w };
        my $pid = spawn(\@cmd, undef, $rdr);
-       die "spawn fast-import failed: $!" unless defined $pid;
        $out_w->autoflush(1);
        $self->{in} = $in_r;
        $self->{out} = $out_w;
@@ -430,7 +429,6 @@ sub add {
 sub run_die ($;$$) {
        my ($cmd, $env, $rdr) = @_;
        my $pid = spawn($cmd, $env, $rdr);
-       defined $pid or die "spawning ".join(' ', @$cmd)." failed: $!";
        waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
        $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
index f14809d25fe361a827dc3f18a21e14a594594f2b..cb5549125c4c0fdc0f5ab2b50e55e081ecf692e2 100644 (file)
@@ -666,7 +666,6 @@ sub is_ancestor ($$$) {
        my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
                qw(merge-base --is-ancestor), $cur, $tip ];
        my $pid = spawn($cmd);
-       defined $pid or die "spawning ".join(' ', @$cmd)." failed: $!";
        waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
        $? == 0;
 }
index bb288b16cbeeb4c7bdf507e6628acfcdca5b78e5..d9cc47e33483cb758d8d4b77918e1be55279f63b 100644 (file)
@@ -23,7 +23,6 @@ sub spamcheck {
 
        my $rdr = { 0 => _msg_to_fh($self, $msg) };
        my ($fh, $pid) = popen_rd($self->{checkcmd}, undef, $rdr);
-       defined $pid or die "failed to popen_rd spamc: $!\n";
        my $r;
        unless (ref $out) {
                my $buf = '';
index 1c74a5964aa59235d51eaa6af7bbb9b37fecb4eb..b02d536866836cec97ecbfc82002793fc59dbd9c 100644 (file)
@@ -219,7 +219,6 @@ sub popen_rd {
        $opts ||= {};
        $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;
index d6d1e9394937c1ea652ccb06b52b41d82cc06470..b3c9561251e1ce4bf3157aea76866d8f0fbaf2e1 100644 (file)
@@ -215,7 +215,6 @@ sub run_script ($;$$) {
                require PublicInbox::Spawn;
                my $cmd = [ key2script($key), @argv ];
                my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
-               defined($pid) or die "spawn: $!";
                if (defined $pid) {
                        my $r = waitpid($pid, 0);
                        defined($r) or die "waitpid: $!";
index 6021de4496a5e08b2504bbf5498a0d0d112427c6..5179432617a561a1d034f550de06b3462c8b0b02 100644 (file)
@@ -777,7 +777,6 @@ sub diff ($$$) {
        my $cmd = [ qw(diff -u), $an, $bn ];
        print STDERR "# MID conflict <$mid>\n";
        my $pid = spawn($cmd, undef, { 1 => 2 });
-       defined $pid or die "diff failed to spawn $!";
        waitpid($pid, 0) == $pid or die "diff did not finish";
        unlink($an, $bn);
 }
index 8a8c1262737034f6415bec853d87c7b2898b2cd3..dfb987e85dd5718648223206e13434b36ff5ca61 100644 (file)
@@ -7,7 +7,6 @@ package PublicInbox::WatchMaildir;
 use strict;
 use warnings;
 use PublicInbox::MIME;
-use PublicInbox::Spawn qw(spawn);
 use PublicInbox::InboxWritable;
 use File::Temp 0.19 (); # 0.19 for ->newdir
 use PublicInbox::Filter::Base qw(REJECT);
index a52dba110c359fa988e4781657d2be81d7fe6d0c..8d6100375e65df772fbe7f0733716b51ddfa5dab 100644 (file)
@@ -136,9 +136,7 @@ sub fingerprint ($) {
        my ($git) = @_;
        # TODO: convert to qspawn for fairness when there's
        # thousands of repos
-       my ($fh, $pid) = $git->popen('show-ref') or
-               die "popen($git->{git_dir} show-ref) failed: $!";
-
+       my ($fh, $pid) = $git->popen('show-ref');
        my $dig = Digest::SHA->new(1);
        while (read($fh, my $buf, 65536)) {
                $dig->add($buf);
index db292c5064a252b48c316b6e4d3d7d43a023a7b0..402099570aca8ed807e2a9c5f3f5537dbd1806f3 100644 (file)
@@ -48,7 +48,6 @@ my $atom_check = eval {
                        2 => fileno($err_fh),
                };
                my $pid = spawn($cmd, undef, $rdr);
-               defined $pid or die "spawn failure: $!";
                while (waitpid($pid, 0) != $pid) {
                        next if $!{EINTR};
                        warn "waitpid(xmlstarlet, $pid) $!";