]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: use autodie for seek+sysseek
authorEric Wong <e@80x24.org>
Sat, 18 Jan 2025 01:26:11 +0000 (01:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jan 2025 22:37:01 +0000 (22:37 +0000)
The underlying lseek(2) syscall won't fail due to HW errors,
only due to usage errors (ESPIPE, EINVAL); so don't waste
code on error checking ourselves and just let autodie check
things during development.

16 files changed:
Documentation/common.perl
lib/PublicInbox/Emergency.pm
lib/PublicInbox/HTTP.pm
lib/PublicInbox/SolverGit.pm
lib/PublicInbox/ViewVCS.pm
lib/PublicInbox/WwwStatic.pm
t/check-www-inbox.perl
t/gcf2.t
t/gzip_filter.t
t/httpd-corner.t
t/import.t
t/ipc.t
t/lei-externals.t
t/lei-p2q.t
t/lei-sigpipe.t
t/mbox_reader.t

index 53bae4959ed0ac555d133a4c5aea24ea50a65bb6..98a06ee1468d6d3d39dcfb09e5184bf9560a5b50 100755 (executable)
@@ -2,6 +2,7 @@
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
+use autodie qw(seek);
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Search;
 my $addr = 'meta@public-inbox.org';
@@ -38,7 +39,7 @@ L<http://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/meta/>
                my $t = time;
                utime($t, $t, $fh);
        } else {
-               seek($fh, 0, SEEK_SET) or die "seek: $!";
+               seek $fh, 0, SEEK_SET;
                truncate($fh, 0) or die "truncate: $!";
                print $fh $s or die "print: $!";
                close $fh or die "close: $!";
index 968d7d6ff7202958403c5817ee688984fba1414a..d3a83408f12283ff08e2ecd2e09227ad31745c1b 100644 (file)
@@ -9,6 +9,7 @@ use Sys::Hostname qw(hostname);
 use IO::Handle; # ->flush
 use Errno qw(EEXIST);
 use File::Path ();
+use autodie qw(seek sysseek);
 
 sub new {
        my ($class, $dir) = @_;
@@ -57,8 +58,8 @@ sub abort {
 sub fh {
        my ($self) = @_;
        my $fh = $self->{fh} or die "BUG: {fh} not open";
-       seek($fh, 0, SEEK_SET) or die "seek: $!";
-       sysseek($fh, 0, SEEK_SET) or die "sysseek: $!";
+       seek $fh, 0, SEEK_SET;
+       sysseek $fh, 0, SEEK_SET;
        $fh;
 }
 
index 88cab544739cb6d4643a701389b5542753281602..80ebad164ab524c4b90dab35474794d9618e8dcd 100644 (file)
@@ -147,10 +147,7 @@ sub app_dispatch {
                $host =~ s/:([0-9]+)\z// and $env->{SERVER_PORT} = $1 + 0;
                $env->{SERVER_NAME} = $host;
        }
-       if (defined $input) {
-               sysseek($input, 0, SEEK_SET) or
-                       die "BUG: psgi.input seek failed: $!";
-       }
+       sysseek($input, 0, SEEK_SET) if defined $input;
        # note: NOT $self->{sock}, we want our close (+ PublicInbox::DS::close),
        # to do proper cleanup:
        $env->{'psgix.io'} = $self; # for ->close or async_pass
index d9465771116bfd0a94bd385d97f1b0dcc289645f..e30761e251ee70c6c9cb45fd7f3d6feafbec8f2f 100644 (file)
@@ -11,7 +11,7 @@ package PublicInbox::SolverGit;
 use strict;
 use v5.10.1;
 use File::Temp 0.19 (); # 0.19 for ->newdir
-use autodie qw(mkdir);
+use autodie qw(mkdir sysseek);
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Git qw(git_unquote git_quote git_exe);
 use PublicInbox::IO qw(write_file);
@@ -342,7 +342,7 @@ sub prepare_index ($) {
        my $in = tmpfile("update-index.$oid_full") or die "tmpfile: $!";
        print $in "$mode_a $oid_full\t$path_a\0" or die "print: $!";
        $in->flush or die "flush: $!";
-       sysseek($in, 0, SEEK_SET) or die "seek: $!";
+       sysseek $in, 0, SEEK_SET;
 
        dbg($self, 'preparing index');
        my $rdr = { 0 => $in };
index d9df671c244ff752b74486b15a3f013b89cfe720..8d937cff0d8e188a62e3bc0f049207cb7bdd7537 100644 (file)
@@ -65,11 +65,10 @@ sub html_page ($$;@) {
 sub dbg_log ($) {
        my ($ctx) = @_;
        my $log = delete $ctx->{lh} // die 'BUG: already captured debug log';
-       if (!CORE::seek($log, 0, SEEK_SET)) {
-               warn "seek(log): $!";
-               return '<pre>debug log seek error</pre>';
-       }
-       $log = eval { PublicInbox::IO::read_all $log } // do {
+       $log = eval {
+               seek $log, 0, SEEK_SET;
+               PublicInbox::IO::read_all $log;
+       } // do {
                warn "read(log): $@";
                return '<pre>debug log read error</pre>';
        };
index d89021930373a89835bda84720119b49e1ae289e..af4eb9601accbe93ed01c96c7e114b219e734b85 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # This package can either be a PSGI response body for a static file
@@ -11,6 +11,7 @@ package PublicInbox::WwwStatic;
 use strict;
 use v5.10.1;
 use parent qw(Exporter);
+use autodie qw(sysseek);
 use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
 use HTTP::Date qw(time2str);
 use HTTP::Status qw(status_message);
@@ -178,8 +179,7 @@ sub getline {
        my $len = $self->{len} or return; # undef, tells server we're done
        my $n = 8192;
        $n = $len if $len < $n;
-       sysseek($self->{in}, $self->{off}, SEEK_SET) or
-                       die "sysseek ($self->{path}): $!";
+       sysseek $self->{in}, $self->{off}, SEEK_SET;
        my $r = sysread($self->{in}, my $buf, $n);
        if (defined $r && $r > 0) { # success!
                $self->{len} = $len - $r;
index 46f9ce1e8b9e71242ec9c1c493f83c30b57613b0..1b9db49e2c9f2cd2740cffaa0a4ebd48f2452b15 100644 (file)
@@ -4,7 +4,8 @@
 # Parallel WWW checker
 my $usage = "$0 [-j JOBS] [-s SLOW_THRESHOLD] URL_OF_INBOX\n";
 use strict;
-use warnings;
+use v5.10.1;
+use autodie qw(sysseek);
 use File::Temp qw(tempfile);
 use GDBM_File;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
index 33f3bbca52ea543c031f37ebe7bff56d74e2a1f8..9f9e8e2003c0fe16acc764393c618a6a09858307 100644 (file)
--- a/t/gcf2.t
+++ b/t/gcf2.t
@@ -1,7 +1,9 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
+use v5.10.1;
+use autodie qw(seek);
 use PublicInbox::TestCommon;
 use Test::More;
 use Fcntl qw(:seek);
@@ -80,18 +82,18 @@ SKIP: {
        $fh->autoflush(1);
 
        ok(!$gcf2->cat_oid(fileno($fh), 'invalid'), 'invalid fails');
-       seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+       seek $fh, 0, SEEK_SET;
        is(do { local $/; <$fh> }, '', 'nothing written');
 
        open $fh, '+>', undef or BAIL_OUT "open: $!";
        ok(!$gcf2->cat_oid(fileno($fh), '0'x40), 'z40 fails');
-       seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+       seek $fh, 0, SEEK_SET;
        is(do { local $/; <$fh> }, '', 'nothing written for z40');
 
        open $fh, '+>', undef or BAIL_OUT "open: $!";
        my $ck_copying = sub {
                my ($desc) = @_;
-               seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+               seek $fh, 0, SEEK_SET;
                is(<$fh>, "$COPYING blob 34520\n", "got expected header $desc");
                my $buf = do { local $/; <$fh> };
                is(chop($buf), "\n", 'got trailing \\n');
@@ -113,7 +115,7 @@ SKIP: {
                fcntl($w, $F_SETPIPE_SZ, 4096) or
                        skip('Linux too old for F_SETPIPE_SZ', 14);
                $w->blocking($blk);
-               seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+               seek $fh, 0, SEEK_SET;
                truncate($fh, 0) or BAIL_OUT "truncate: $!";
                my $pid = fork // BAIL_OUT "fork: $!";
                if ($pid == 0) {
index 97eac2d04851e1f274327223340b991f3e1b8f54..f827510f470156d545f48789e67f421219a2806e 100644 (file)
@@ -16,7 +16,7 @@ require_ok 'PublicInbox::GzipFilter';
        ok($filter->write("hello"), 'wrote something');
        ok($filter->write("world"), 'wrote more');
        $filter->close;
-       seek($fh, 0, SEEK_SET) or die;
+       seek $fh, 0, SEEK_SET;
        IO::Uncompress::Gunzip::gunzip($fh => \(my $buf));
        is($buf, 'helloworld', 'buffer matches');
 }
index 125610d60839b5ecfd47e2cb1f3411a6a66f8d1d..e653f1e1aecebd3cc6670d3b0eca72917df2cb51 100644 (file)
@@ -5,7 +5,7 @@
 # generic PSGI/Plack apps.
 use v5.12; use PublicInbox::TestCommon;
 use Time::HiRes qw(gettimeofday tv_interval);
-use autodie qw(getsockopt setsockopt);
+use autodie qw(getsockopt seek setsockopt);
 use PublicInbox::Spawn qw(spawn popen_rd);
 require_mods '-httpd';
 use PublicInbox::SHA qw(sha1_hex);
@@ -676,7 +676,7 @@ SKIP: {
                $req = GET('http://example.com/psgi-yield-enoent');
                $res = $cb->($req);
                is($res->code, 500, 'got error on ENOENT');
-               seek($tmperr, 0, SEEK_SET) or die;
+               seek $tmperr, 0, SEEK_SET;
                my $errbuf = do { local $/; <$tmperr> };
                like($errbuf, qr/this-better-not-exist/,
                        'error logged about missing command');
index 7e2432e7ee8250a8b103ab452fc87761f83411e3..48416eb2ee1057571efe76040d1966c82018bc85 100644 (file)
@@ -3,6 +3,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use v5.10.1;
 use strict;
+use autodie qw(seek);
 use PublicInbox::Eml;
 use PublicInbox::Smsg;
 use PublicInbox::Git;
@@ -36,7 +37,7 @@ SKIP: {
        open my $in, '+<', undef or BAIL_OUT "open(+<): $!";
        print $in $mime->as_string or die "write failed: $!";
        $in->flush or die "flush failed: $!";
-       seek($in, 0, SEEK_SET) or die "seek: $!";
+       seek $in, 0, SEEK_SET;
        chomp(my $hashed_obj = xqx(\@cmd, undef, { 0 => $in }));
        is($?, 0, 'hash-object');
        is($hashed_obj, $smsg->{blob}, "blob object_id matches exp");
diff --git a/t/ipc.t b/t/ipc.t
index 23ae2e7b2455dbb0b7febdfd25702408b36722b0..fc6f96a2330af43f46c578aca12a0bdefc74f051 100644 (file)
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -2,6 +2,7 @@
 # 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 PublicInbox::TestCommon;
 use Fcntl qw(SEEK_SET);
 use PublicInbox::SHA qw(sha1_hex);
@@ -176,7 +177,7 @@ SKIP: {
 $ipc->wq_close;
 SKIP: {
        skip 'Socket::MsgHdr or Inline::C missing', 11 if !$ppids[0];
-       seek($warn, 0, SEEK_SET) or BAIL_OUT;
+       seek $warn, 0, SEEK_SET;
        my @warn = <$warn>;
        is(scalar(@warn), 2, 'warned 3 times');
        like($warn[0], qr/ wq_worker: /, '2nd warned from wq_worker');
index 4f2dd6baf57e38729b4ced46a987e1fead6de860..32e1255b8cf5a5119cd7a7f2af4de0c7dc33f409 100644 (file)
@@ -1,8 +1,9 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use Fcntl qw(SEEK_SET);
+use autodie qw(seek);
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Xapian));
 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
@@ -200,7 +201,7 @@ test_lei(sub {
                open my $fh, '+>', undef or BAIL_OUT $!;
                $fh->autoflush(1);
                print $fh 's:use d:..5.days.from.now' or BAIL_OUT $!;
-               seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
+               seek $fh, 0, SEEK_SET;
                lei_ok([qw(q -q --stdin)], undef, { %$lei_opt, 0 => $fh },
                                \'--stdin on regular file works');
                like($lei_out, qr/use boolean/, '--stdin on regular file');
index 44f37d1951734df49ca5e17a451febc6e4f3e8bc..778aa68f19a875743a32d6cbdf59aeb9a95bd909 100644 (file)
@@ -1,7 +1,8 @@
 #!perl -w
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
+use autodie qw(sysseek);
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Xapian));
 
@@ -15,7 +16,7 @@ test_lei(sub {
        lei_ok([qw(p2q -w dfpost -)], undef, { %$lei_opt, 0 => $fh });
        is($lei_out, "dfpost:6e006fd73b1d\n", '--stdin') or diag $lei_err;
 
-       sysseek($fh, 0, 0) or xbail "lseek: $!";
+       sysseek $fh, 0, 0;
        lei_ok([qw(p2q -w dfpost)], undef, { %$lei_opt, 0 => $fh });
        is($lei_out, "dfpost:6e006fd73b1d\n", 'implicit --stdin');
 
index c01d9f8362feaa35b28362083a5ef68c68c2dc2f..db4f9288ce7442e2c82dac16ba47a75ff78a2523 100644 (file)
@@ -55,7 +55,7 @@ EOM
                close $w;
                vec(my $rvec = '', fileno($r), 1) = 1;
                if (!select($rvec, undef, undef, 30)) {
-                       seek($errfh, 0, 0);
+                       seek $errfh, 0, 0;
                        my $s = do { local $/; <$errfh> };
                        xbail "lei q had no output after 30s, stderr=$s";
                }
@@ -64,7 +64,7 @@ EOM
                $tp->join;
                ok(WIFSIGNALED($?), "signaled @$out");
                is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
-               seek($errfh, 0, 0);
+               seek $errfh, 0, 0;
                my $s = do { local $/; <$errfh> };
                is($s, '', "quiet after sigpipe @$out");
        }
index 14248a2dd0c6a21ed34c03fee4ab9c2a7907c656..1fa9068e37175296fc1b974b8a7f98e2b3f732e6 100644 (file)
@@ -1,9 +1,9 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
-use Test::More;
+use autodie qw(seek);
 use PublicInbox::TestCommon;
 use List::Util qw(shuffle);
 use PublicInbox::Eml;
@@ -52,7 +52,7 @@ my $check_fmt = sub {
                my $buf = $eml2mbox->($eml);
                print $fh $$buf or BAIL_OUT "print $!";
        }
-       seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+       seek $fh, 0, SEEK_SET;
        $reader->$fmt($fh, sub {
                my ($eml) = @_;
                $eml->header_set('Status');