about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-07 21:24:09 +0000
committerEric Wong <e@80x24.org>2023-10-08 18:54:48 +0000
commited1ad9b3b6ea3e6e22deaaf54fdc8230a3b09b8c (patch)
treedce43f04eaf5818ab783bcc859001c4e34fd618e /lib/PublicInbox
parent1661ff8e21f3cb1df1a3fc00d917f404f4eae734 (diff)
downloadpublic-inbox-ed1ad9b3b6ea3e6e22deaaf54fdc8230a3b09b8c.tar.gz
Specifying {cb_args} in the options hash felt awkward to me.
Instead, just use the Perl stack like we do with awaitpid()
and pass the list down directly.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiToMail.pm4
-rw-r--r--lib/PublicInbox/ProcessIO.pm4
-rw-r--r--lib/PublicInbox/Qspawn.pm4
-rw-r--r--lib/PublicInbox/Spawn.pm10
4 files changed, 12 insertions, 10 deletions
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index f56ad330..8771592d 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -162,8 +162,8 @@ sub _post_augment_mbox { # open a compressor process from top-level lei-daemon
         my ($r, $w) = @{delete $lei->{zpipe}};
         my $rdr = { 0 => $r, 1 => $lei->{1}, 2 => $lei->{2}, pgid => 0 };
         my $pid = spawn($cmd, undef, $rdr);
-        $lei->{1} = PublicInbox::ProcessIO->maybe_new($pid, $w, {
-                        cb_arg => [\&reap_compress, $lei, $cmd, $lei->{1} ] });
+        $lei->{1} = PublicInbox::ProcessIO->maybe_new($pid, $w,
+                                \&reap_compress, $lei, $cmd, $lei->{1});
 }
 
 # --augment existing output destination, with deduplication
diff --git a/lib/PublicInbox/ProcessIO.pm b/lib/PublicInbox/ProcessIO.pm
index eeb66139..5a81e3a6 100644
--- a/lib/PublicInbox/ProcessIO.pm
+++ b/lib/PublicInbox/ProcessIO.pm
@@ -9,10 +9,10 @@ use PublicInbox::DS qw(awaitpid);
 use Symbol qw(gensym);
 
 sub maybe_new {
-        my ($cls, $pid, $fh, $opt) = @_;
+        my ($cls, $pid, $fh, @cb_arg) = @_;
         return ($fh, $pid) if wantarray;
         my $s = gensym;
-        tie *$s, $cls, $pid, $fh, @{$opt->{cb_arg} // []};
+        tie *$s, $cls, $pid, $fh, @cb_arg;
         $s;
 }
 
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index ea7ae647..0e52617c 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -58,10 +58,10 @@ sub _do_spawn {
         }
         $self->{cmd} = $cmd;
         $self->{-quiet} = 1 if $o{quiet};
-        $o{cb_arg} = [ \&waitpid_err, $self ];
         eval {
                 # popen_rd may die on EMFILE, ENFILE
-                $self->{rpipe} = popen_rd($cmd, $cmd_env, \%o) // die "E: $!";
+                $self->{rpipe} = popen_rd($cmd, $cmd_env, \%o,
+                                        \&waitpid_err, $self);
                 $limiter->{running}++;
                 $start_cb->($self); # EPOLL_CTL_ADD may ENOSPC/ENOMEM
         };
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index cb8b21c6..ec256698 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -366,15 +366,17 @@ sub spawn ($;$$) {
 }
 
 sub popen_rd {
-        my ($cmd, $env, $opt) = @_;
+        my ($cmd, $env, $opt, @cb_arg) = @_;
         pipe(my $r, local $opt->{1}) or die "pipe: $!\n";
-        PublicInbox::ProcessIO->maybe_new(spawn($cmd, $env, $opt), $r, $opt)
+        my $pid = spawn($cmd, $env, $opt);
+        PublicInbox::ProcessIO->maybe_new($pid, $r, @cb_arg);
 }
 
 sub popen_wr {
-        my ($cmd, $env, $opt) = @_;
+        my ($cmd, $env, $opt, @cb_arg) = @_;
         pipe(local $opt->{0}, my $w) or die "pipe: $!\n";
-        PublicInbox::ProcessIO->maybe_new(spawn($cmd, $env, $opt), $w, $opt)
+        my $pid = spawn($cmd, $env, $opt);
+        PublicInbox::ProcessIO->maybe_new($pid, $w, @cb_arg)
 }
 
 sub run_wait ($;$$) {