]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
rename ProcessPipe to ProcessIO
authorEric Wong <e@80x24.org>
Sat, 7 Oct 2023 21:24:08 +0000 (21:24 +0000)
committerEric Wong <e@80x24.org>
Sun, 8 Oct 2023 18:54:47 +0000 (18:54 +0000)
Since we deal with pipes (of either direction) and bidirectional
stream sockets for this class, it's better to remove the `Pipe'
from the name and replace it with `IO' to communicate that it
works for any form of IO::Handle-like object tied to a process.

MANIFEST
lib/PublicInbox/Gcf2Client.pm
lib/PublicInbox/Git.pm
lib/PublicInbox/HTTPD/Async.pm
lib/PublicInbox/LeiRediff.pm
lib/PublicInbox/LeiToMail.pm
lib/PublicInbox/ProcessIO.pm [moved from lib/PublicInbox/ProcessPipe.pm with 86% similarity]
lib/PublicInbox/Qspawn.pm
lib/PublicInbox/Spamcheck/Spamc.pm
lib/PublicInbox/Spawn.pm
t/spawn.t

index 689c6bf6ee1a1b6a859e378b8d5e4fccbc3ce96c..c972818faad283e075529a75c0661c7d67e30366 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -318,7 +318,7 @@ lib/PublicInbox/OverIdx.pm
 lib/PublicInbox/POP3.pm
 lib/PublicInbox/POP3D.pm
 lib/PublicInbox/PktOp.pm
-lib/PublicInbox/ProcessPipe.pm
+lib/PublicInbox/ProcessIO.pm
 lib/PublicInbox/Qspawn.pm
 lib/PublicInbox/Reply.pm
 lib/PublicInbox/RepoAtom.pm
index 4a0348b459862558fc32c441996b274feb7e7399..f63a0335c99172d553b0927ea63d0e9b2241b29b 100644 (file)
@@ -10,7 +10,7 @@ use PublicInbox::Gcf2; # fails if Inline::C or libgit2-dev isn't available
 use PublicInbox::Spawn qw(spawn);
 use Socket qw(AF_UNIX SOCK_STREAM);
 use PublicInbox::Syscall qw(EPOLLIN);
-use PublicInbox::ProcessPipe;
+use PublicInbox::ProcessIO;
 use autodie qw(socketpair);
 
 # fields:
@@ -33,7 +33,7 @@ sub new  {
        my $cmd = [$^X, $^W ? ('-w') : (),
                        qw[-MPublicInbox::Gcf2 -e PublicInbox::Gcf2::loop]];
        my $pid = spawn($cmd, $env, $opt);
-       my $sock = PublicInbox::ProcessPipe->maybe_new($pid, $s1);
+       my $sock = PublicInbox::ProcessIO->maybe_new($pid, $s1);
        $self->{inflight} = [];
        $self->{epwatch} = \undef; # for Git->cleanup
        $self->SUPER::new($sock, EPOLLIN);
index 0fd621e1cb6bc7ef9b65c39f6f52b6272dd93e39..94d5dcee89ec6cda81681e3c2ca834094c7f3bc5 100644 (file)
@@ -165,7 +165,7 @@ sub _sock_cmd {
                                                $self->fail("tmpfile($id): $!");
        }
        my $pid = spawn(\@cmd, undef, $opt);
-       $self->{sock} = PublicInbox::ProcessPipe->maybe_new($pid, $s1);
+       $self->{sock} = PublicInbox::ProcessIO->maybe_new($pid, $s1);
 }
 
 sub poll_in ($) { IO::Poll::_poll($RDTIMEO, fileno($_[0]), my $ev = POLLIN) }
@@ -626,7 +626,7 @@ sub cleanup_if_unlinked {
        my $ret = 0;
        for my $obj ($self, ($self->{ck} // ())) {
                my $sock = $obj->{sock} // next;
-               my PublicInbox::ProcessPipe $pp = tied *$sock; # ProcessPipe
+               my PublicInbox::ProcessIO $pp = tied *$sock; # ProcessIO
                my $pid = $pp->{pid} // next;
                open my $fh, '<', "/proc/$pid/maps" or return cleanup($self, 1);
                while (<$fh>) {
index 7bbab1e1cd65c22d2a895f5a99b5924fa172afd5..b9d2159c6caba023bd262561ff83dbdcff6a7214 100644 (file)
@@ -37,7 +37,7 @@ sub new {
                arg => $arg, # arg for $cb
                end_obj => $end_obj, # like END{}, can ->event_step
        }, $class;
-       my $pp = tied *$io; # ProcessPipe
+       my $pp = tied *$io; # ProcessIO
        $pp->{fh}->blocking(0) // die "$io->blocking(0): $!";
        $self->SUPER::new($io, EPOLLIN);
 }
index a886931c1921fafc5ddf896b6f090fb5c1ecac99..b894342be8d83bd9dd2e56757b99a44cc96b6888 100644 (file)
@@ -152,7 +152,7 @@ sub requote ($$) {
        # $^X (perl) is overkill, but maybe there's a weird system w/o sed
        my ($w, $pid) = popen_wr([$^X, '-pe', "s/^/$pfx/"], $lei->{env}, $opt);
        $w->autoflush(1);
-       binmode $w, ':utf8'; # incompatible with ProcessPipe due to syswrite
+       binmode $w, ':utf8'; # incompatible with ProcessIO due to syswrite
        $lei->{1} = $w;
        PublicInbox::OnDestroy->new(\&wait_requote, $lei, $pid, $old_1);
 }
index f239da822fe50638d61738be69ab2da3c9813c88..f56ad330d87f305d2a267c55bd6a5e4ad798794c 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC);
 use PublicInbox::Eml;
-use PublicInbox::ProcessPipe;
+use PublicInbox::ProcessIO;
 use PublicInbox::Spawn qw(spawn);
 use IO::Handle; # ->autoflush
 use Fcntl qw(SEEK_SET SEEK_END O_CREAT O_EXCL O_WRONLY);
@@ -162,7 +162,7 @@ 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::ProcessPipe->maybe_new($pid, $w, {
+       $lei->{1} = PublicInbox::ProcessIO->maybe_new($pid, $w, {
                        cb_arg => [\&reap_compress, $lei, $cmd, $lei->{1} ] });
 }
 
similarity index 86%
rename from lib/PublicInbox/ProcessPipe.pm
rename to lib/PublicInbox/ProcessIO.pm
index ba2c1ecb9662cc58f3eec089c051e20faae0e098..eeb66139be6621fa1e45879f6403db7245fd84a9 100644 (file)
@@ -1,11 +1,9 @@
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
-# a tied handle for auto reaping of children tied to a read-only pipe, see perltie(1)
-# DO NOT use this as-is for bidirectional pipes/sockets (e.g. in PublicInbox::Git),
-# both ends of the pipe must be at the same level of the Perl object hierarchy
-# to ensure orderly destruction.
-package PublicInbox::ProcessPipe;
+# a tied handle for auto reaping of children tied to a pipe or socket,
+# see perltie(1) for details.
+package PublicInbox::ProcessIO;
 use v5.12;
 use PublicInbox::DS qw(awaitpid);
 use Symbol qw(gensym);
index 5e4fd5cb8541a2a8202d188ae1fd73c88fe64188..ea7ae647014d0dbcf5fcd36c48d452ff857233cf 100644 (file)
@@ -124,7 +124,7 @@ sub finish ($;$) {
 
        # we can safely finalize if pipe was closed before, or if
        # {_err} is defined by waitpid_err.  Deleting {rpipe} will
-       # trigger PublicInbox::ProcessPipe::DESTROY -> waitpid_err,
+       # trigger PublicInbox::ProcessIO::DESTROY -> waitpid_err,
        # but it may not fire right away if inside the event loop.
        my $closed_before = !delete($self->{rpipe});
        finalize($self) if $closed_before || defined($self->{_err});
@@ -251,7 +251,7 @@ sub psgi_return_init_cb { # this may be PublicInbox::HTTPD::Async {cb}
        if (ref($r) ne 'ARRAY' || scalar(@$r) == 3) { # error
                if ($async) { # calls rpipe->close && ->event_step
                        $async->close; # PublicInbox::HTTPD::Async::close
-               } else { # generic PSGI, use PublicInbox::ProcessPipe::CLOSE
+               } else { # generic PSGI, use PublicInbox::ProcessIO::CLOSE
                        delete($self->{rpipe})->close;
                        event_step($self);
                }
index 726866c8577e2f4da24c65eaa8a57161d0b8e202..cba33a6661e3826cf48c0e3305a72a00990e34e9 100644 (file)
@@ -27,7 +27,7 @@ sub spamcheck {
                $out = \$buf;
        }
        $$out = do { local $/; <$fh> };
-       close $fh; # PublicInbox::ProcessPipe::CLOSE
+       close $fh; # PublicInbox::ProcessIO::CLOSE
        ($? || $$out eq '') ? 0 : 1;
 }
 
index 4c7e0f80e51e01a48436104add0837f265283c79..cb8b21c6ac57df39099b67fb9e75ccd93894589d 100644 (file)
@@ -21,7 +21,7 @@ use PublicInbox::Lock;
 use Fcntl qw(SEEK_SET);
 use IO::Handle ();
 use Carp qw(croak);
-use PublicInbox::ProcessPipe;
+use PublicInbox::ProcessIO;
 our @EXPORT_OK = qw(which spawn popen_rd popen_wr run_die run_wait);
 our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA);
 
@@ -368,13 +368,13 @@ sub spawn ($;$$) {
 sub popen_rd {
        my ($cmd, $env, $opt) = @_;
        pipe(my $r, local $opt->{1}) or die "pipe: $!\n";
-       PublicInbox::ProcessPipe->maybe_new(spawn($cmd, $env, $opt), $r, $opt)
+       PublicInbox::ProcessIO->maybe_new(spawn($cmd, $env, $opt), $r, $opt)
 }
 
 sub popen_wr {
        my ($cmd, $env, $opt) = @_;
        pipe(local $opt->{0}, my $w) or die "pipe: $!\n";
-       PublicInbox::ProcessPipe->maybe_new(spawn($cmd, $env, $opt), $w, $opt)
+       PublicInbox::ProcessIO->maybe_new(spawn($cmd, $env, $opt), $w, $opt)
 }
 
 sub run_wait ($;$$) {
index 04589437efbbe652ad302a17680a4819fecf0f2d..be5aaf9fb90af8618b432b1eb89b5280084239c0 100644 (file)
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -149,8 +149,8 @@ EOF
        $fh = popen_rd(['true'], undef, { cb_arg => [sub { @c = caller }] });
        undef $fh; # ->DESTROY
        ok(scalar(@c), 'callback fired by ->DESTROY');
-       ok(grep(!m[/PublicInbox/ProcessPipe\.pm\z], @c),
-               'callback not invoked by ProcessPipe');
+       ok(grep(!m[/PublicInbox/ProcessIO\.pm\z], @c),
+               'callback not invoked by ProcessIO');
 }
 
 { # children don't wait on siblings