package PublicInbox::IPC;
use v5.12;
use parent qw(Exporter);
-use autodie qw(close pipe read socketpair);
+use autodie qw(close pipe read send socketpair);
use Errno qw(EAGAIN EINTR);
use Carp qw(croak);
use PublicInbox::DS qw(awaitpid);
my $buf = ipc_freeze([$sub, @args]);
for my $bcast1 (values %$wkr) {
my $sock = $bcast1 // $self->{-wq_s1} // next;
- send($sock, $buf, 0) // croak "send: $!";
+ send($sock, $buf, 0);
# XXX shouldn't have to deal with EMSGSIZE here...
}
}
package PublicInbox::POP3D;
use v5.12;
use parent qw(PublicInbox::Lock);
+use autodie qw(open);
use DBI qw(:sql_types); # SQL_BLOB
use Carp ();
use File::Temp 0.19 (); # 0.19 for ->newdir
# ensure the interprocess fcntl lock file exists
$f = "$self->{pi_cfg}->{'publicinbox.pop3state'}/txn.locks";
- open my $fh, '+>>', $f or Carp::croak("open($f): $!");
+ open my $fh, '+>>', $f;
$self->{txn_fh} = $fh;
create_state_tables($self, $dbh);
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use v5.12;
-use autodie qw(seek);
+use autodie qw(fork open pipe seek);
use PublicInbox::TestCommon;
+use PublicInbox::IO qw(try_cat);
use Fcntl qw(SEEK_SET);
use PublicInbox::SHA qw(sha1_hex);
require_mods(qw(Storable||Sereal));
my ($tmpdir, $for_destroy) = tmpdir();
state $once = eval <<'';
package PublicInbox::IPC;
-use strict;
+use v5.12;
+use autodie qw(open);
use PublicInbox::SHA qw(sha1_hex);
sub test_array { qw(test array) }
sub test_scalar { 'scalar' }
}
sub test_append_pid {
my ($self, $file) = @_;
- open my $fh, '>>', $file or die "open: $!";
+ open my $fh, '>>', $file;
$fh->autoflush(1);
print $fh "$$\n" or die "print: $!";
}
$ipc->ipc_worker_stop; # idempotent
# work queues
-pipe(my ($ra, $wa)) or BAIL_OUT $!;
-pipe(my ($rb, $wb)) or BAIL_OUT $!;
-pipe(my ($rc, $wc)) or BAIL_OUT $!;
-open my $warn, '+>', undef or BAIL_OUT;
+pipe(my $ra, my $wa);
+pipe(my $rb, my $wb);
+pipe(my $rc, my $wc);
+open my $warn, '+>', undef;
$warn->autoflush(0);
local $SIG{__WARN__} = sub { print $warn "PID:$$ ", @_ };
my @ppids;
-open my $agpl, '<', 'COPYING' or BAIL_OUT "AGPL-3 missing: $!";
-my $big = do { local $/; <$agpl> } // BAIL_OUT "read: $!";
-close $agpl or BAIL_OUT "close: $!";
+my $big = try_cat('COPYING') || BAIL_OUT "try_cat(COPYING): $!";
for my $t ('worker', 'worker again') {
my $ppid = $ipc->wq_workers_start('wq', 1);
skip 'Socket::MsgHdr or Inline::C missing', 3 if !$ppids[0];
is_xdeeply(\@ppids, [$$, undef],
'parent pid returned in wq_workers_start');
- my $pid = fork // BAIL_OUT $!;
+ my $pid = fork;
if ($pid == 0) {
use POSIX qw(_exit);
$ipc->wq_io_do('test_write_each_fd', [ $wa, $wb, $wc ], $$);
is($ipc->wq_workers_start('wq', 2), $$, 'workers started again');
$ipc->wq_broadcast('test_append_pid', "$tmpdir/append_pid");
$ipc->wq_close;
- open my $fh, '<', "$tmpdir/append_pid" or BAIL_OUT "open: $!";
- chomp(my @pids = <$fh>);
+ chomp(my @pids = try_cat("$tmpdir/append_pid"));
my %pids = map { $_ => 1 } grep(/\A[0-9]+\z/, @pids);
is(scalar keys %pids, 2, 'broadcast hit both PIDs');
}