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
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:
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);
$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) }
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>) {
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);
}
# $^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);
}
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);
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} ] });
}
# 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);
# 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});
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);
}
$out = \$buf;
}
$$out = do { local $/; <$fh> };
- close $fh; # PublicInbox::ProcessPipe::CLOSE
+ close $fh; # PublicInbox::ProcessIO::CLOSE
($? || $$out eq '') ? 0 : 1;
}
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);
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 ($;$$) {
$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