]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
daemon: slightly simplify xap_helper spawning
authorEric Wong <e@80x24.org>
Thu, 27 Feb 2025 00:08:17 +0000 (00:08 +0000)
committerEric Wong <e@80x24.org>
Tue, 4 Mar 2025 07:54:12 +0000 (07:54 +0000)
Avoid typing the fully-qualified global $XHC variable twice in
spawn_xh.  We'll also delay loading of XhcMset until successful
spawn and improve the error message in case of error.  There's
also no need to conditionally local-ize
$PublicInbox::Search::XHC, so do it unconditionally to reduce
branches.

lib/PublicInbox/Daemon.pm

index e00e0a78f2302b39eabd6f57777b8711cb70ed34..5d93f81fe45170ddafc95045a059591652aa5730 100644 (file)
@@ -390,19 +390,19 @@ sub worker_quit { # $_[0] = signal name or number (unused)
 
 sub spawn_xh () {
        $xh_workers // return;
-       require PublicInbox::XhcMset;
        local $) = $gid if defined $gid;
        local $( = $gid if defined $gid;
        local $> = $uid if defined $uid;
        local $< = $uid if defined $uid;
-       $PublicInbox::Search::XHC = eval {
+       my $xhc = $PublicInbox::Search::XHC = eval {
                local $ENV{STDERR_PATH} = $stderr;
                local $ENV{STDOUT_PATH} = $stdout;
                PublicInbox::XapClient::start_helper('-j', $xh_workers)
        };
        if ($@) {
-               warn "E: $@";
-       } elsif (my $xhc = $PublicInbox::Search::XHC) {
+               warn "E: $@ (will attempt to continue w/o xapian-helpers)\n";
+       } elsif ($xhc) {
+               require PublicInbox::XhcMset;
                $xhc->{io}->blocking(0);
                awaitpid($xhc->{io}->attached_pid, \&respawn_xh);
        }
@@ -746,7 +746,7 @@ sub run {
        local $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
        local %WORKER_SIG = %WORKER_SIG;
        local $PublicInbox::XapClient::tries = 0;
-       local $PublicInbox::Search::XHC if defined($xh_workers);
+       local $PublicInbox::Search::XHC;
 
        daemon_loop();
        # $unlink_on_leave runs