From 537ce9bde088bb9e74e9870909acbc3870032b5e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 Aug 2025 00:33:32 +0000 Subject: [PATCH] use autodie in more places (extindex, pop3d, ipc) Another gradual step towards autodie-ification of our codebase. --- lib/PublicInbox/ExtSearchIdx.pm | 3 ++- lib/PublicInbox/IPC.pm | 4 ++-- lib/PublicInbox/POP3D.pm | 3 ++- t/ipc.t | 25 ++++++++++++------------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 1fd86e059..875928689 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -21,6 +21,7 @@ package PublicInbox::ExtSearchIdx; use strict; use v5.10.1; use parent qw(PublicInbox::ExtSearch PublicInbox::Umask PublicInbox::Lock); +use autodie qw(mkdir); use Carp qw(croak carp); use Scalar::Util qw(blessed); use Sys::Hostname qw(hostname); @@ -1278,7 +1279,7 @@ sub idx_init { # similar to V2Writable } } } elsif ($!{ENOENT}) { - mkdir($pd) or die "mkdir($pd): $!"; + mkdir $pd; } else { die "opendir($pd): $!"; } diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 806653dca..1395c4625 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -10,7 +10,7 @@ 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); @@ -265,7 +265,7 @@ sub wq_broadcast { 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... } } diff --git a/lib/PublicInbox/POP3D.pm b/lib/PublicInbox/POP3D.pm index a30fc6770..8eefba80d 100644 --- a/lib/PublicInbox/POP3D.pm +++ b/lib/PublicInbox/POP3D.pm @@ -5,6 +5,7 @@ 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 @@ -140,7 +141,7 @@ sub state_dbh_new { # 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); diff --git a/t/ipc.t b/t/ipc.t index fc6f96a23..47c361035 100644 --- a/t/ipc.t +++ b/t/ipc.t @@ -2,8 +2,9 @@ # Copyright (C) all contributors # License: AGPL-3.0+ 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)); @@ -11,7 +12,8 @@ require_ok 'PublicInbox::IPC'; 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' } @@ -33,7 +35,7 @@ sub test_sha { } 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: $!"; } @@ -96,16 +98,14 @@ $test->('local'); $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); @@ -147,7 +147,7 @@ SKIP: { 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 ], $$); @@ -187,8 +187,7 @@ SKIP: { 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'); } -- 2.47.3