]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
extindex: improve error checking with try_cat
authorEric Wong <e@80x24.org>
Wed, 13 Aug 2025 21:42:47 +0000 (21:42 +0000)
committerEric Wong <e@80x24.org>
Fri, 15 Aug 2025 12:30:50 +0000 (12:30 +0000)
PublicInbox::IO::try_cat will detect read(2) errors properly
instead of relying on the readline perlop for error checking.

lib/PublicInbox/ExtSearchIdx.pm

index 923de7873a4bb0fac972e63ad06fc9f357e943ee..93107590899ae197683dc32f90049a294ae9e5db 100644 (file)
@@ -40,6 +40,7 @@ use PublicInbox::DS qw(now add_timer);
 use DBI qw(:sql_types); # SQL_BLOB
 use PublicInbox::Admin qw(fmt_localtime);
 use PublicInbox::Config qw(rel2abs_collapsed);
+use PublicInbox::IO qw(try_cat);
 
 sub new {
        my (undef, $dir, $opt) = @_;
@@ -698,8 +699,7 @@ sub host_ident () {
        # these while this process is running and we always want to be
        # able to release locks taken by this process.
        state $retval = hostname . '-' . do {
-               my $m; # machine-id(5) is systemd
-               if (open(my $fh, '<', '/etc/machine-id')) { $m = <$fh> }
+               my $m = try_cat '/etc/machine-id'; # machine-id(5) is systemd
                # (g)hostid(1) is in GNU coreutils, kern.hostid is most BSDs
                chomp($m ||= `{ sysctl -n kern.hostid ||
                                hostid || ghostid; } 2>/dev/null`