From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9146A1F4A6 for ; Sat, 7 Oct 2023 21:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696713851; bh=It0UCJjxjXpKQVSDWDTejtfxdq1Vt9UbsdcB1nW1fDM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fhRB7HDtHyneuHoNo5jkzNgndMPxA/ZxPwQRDGu1RXyfVBXGWBjGxJB1BelfDSAPI 4QpwTNuZa1OZcWuEOd58sV+I/TOXvLceyQsecyQc+xas2+CppknLPmENCzGuWrbZrQ Yyh9VWkRL/0pIkqUelMC+Toq5G9un0s++Fmqt/x8= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 7/9] rename ProcessPipe to ProcessIO Date: Sat, 7 Oct 2023 21:24:08 +0000 Message-ID: <20231007212410.297785-8-e@80x24.org> In-Reply-To: <20231007212410.297785-1-e@80x24.org> References: <20231007212410.297785-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 2 +- lib/PublicInbox/Gcf2Client.pm | 4 ++-- lib/PublicInbox/Git.pm | 4 ++-- lib/PublicInbox/HTTPD/Async.pm | 2 +- lib/PublicInbox/LeiRediff.pm | 2 +- lib/PublicInbox/LeiToMail.pm | 4 ++-- lib/PublicInbox/{ProcessPipe.pm => ProcessIO.pm} | 8 +++----- lib/PublicInbox/Qspawn.pm | 4 ++-- lib/PublicInbox/Spamcheck/Spamc.pm | 2 +- lib/PublicInbox/Spawn.pm | 6 +++--- t/spawn.t | 4 ++-- 11 files changed, 20 insertions(+), 22 deletions(-) rename lib/PublicInbox/{ProcessPipe.pm => ProcessIO.pm} (86%) diff --git a/MANIFEST b/MANIFEST index 689c6bf6..c972818f 100644 --- 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 diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm index 4a0348b4..f63a0335 100644 --- a/lib/PublicInbox/Gcf2Client.pm +++ b/lib/PublicInbox/Gcf2Client.pm @@ -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); diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 0fd621e1..94d5dcee 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -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>) { diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 7bbab1e1..b9d2159c 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -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); } diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm index a886931c..b894342b 100644 --- a/lib/PublicInbox/LeiRediff.pm +++ b/lib/PublicInbox/LeiRediff.pm @@ -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); } diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index f239da82..f56ad330 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -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} ] }); } diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessIO.pm similarity index 86% rename from lib/PublicInbox/ProcessPipe.pm rename to lib/PublicInbox/ProcessIO.pm index ba2c1ecb..eeb66139 100644 --- a/lib/PublicInbox/ProcessPipe.pm +++ b/lib/PublicInbox/ProcessIO.pm @@ -1,11 +1,9 @@ # Copyright (C) all contributors # License: AGPL-3.0+ -# 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); diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index 5e4fd5cb..ea7ae647 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -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); } diff --git a/lib/PublicInbox/Spamcheck/Spamc.pm b/lib/PublicInbox/Spamcheck/Spamc.pm index 726866c8..cba33a66 100644 --- a/lib/PublicInbox/Spamcheck/Spamc.pm +++ b/lib/PublicInbox/Spamcheck/Spamc.pm @@ -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; } diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 4c7e0f80..cb8b21c6 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -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 ($;$$) { diff --git a/t/spawn.t b/t/spawn.t index 04589437..be5aaf9f 100644 --- 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