]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: use cached $daemon_pid when possible
authorEric Wong <e@80x24.org>
Thu, 9 Nov 2023 10:09:35 +0000 (10:09 +0000)
committerEric Wong <e@80x24.org>
Thu, 9 Nov 2023 21:53:47 +0000 (21:53 +0000)
->lei_daemon_pid can only be called in the top-level daemon
process when $daemon_pid is valid, so avoid a getpid(2) syscall
in those cases.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiUp.pm

index 2832db63d1dbe747dff46a4800bfda49e081bd9a..f32e5bbcbdef5fc7dc7cf34c6eb6270551732c68 100644 (file)
@@ -927,7 +927,7 @@ sub _config {
        run_wait($cmd, \%env, \%opt) ? ($err_ok ? undef : fail($self, $?)) : 1;
 }
 
-sub lei_daemon_pid { puts shift, $$ }
+sub lei_daemon_pid { puts shift, $daemon_pid }
 
 sub lei_daemon_kill {
        my ($self) = @_;
index cd2337b492d71dda9dd816bb8306145600a62fa6..0faa180d98284fd967cb3dc734e93cdc91dec205 100644 (file)
@@ -11,6 +11,7 @@ use PublicInbox::LeiSavedSearch; # OverIdx
 use PublicInbox::DS;
 use PublicInbox::PktOp;
 use PublicInbox::LeiFinmsg;
+use PublicInbox::LEI;
 my $REMOTE_RE = qr!\A(?:imap|http)s?://!i; # http(s) will be for JMAP
 
 sub up1 ($$) {
@@ -92,7 +93,6 @@ sub redispatch_all ($$) {
        $op_c->{ops} = { '' => [ $lei->can('dclose'), $lei ] };
        my @first_batch = splice(@$upq, 0, $j); # initial parallelism
        $lei->{-upq} = $upq;
-       $lei->{daemon_pid} = $$;
        $lei->event_step_init; # wait for client disconnects
        for my $out (@first_batch) {
                PublicInbox::DS::requeue(
@@ -212,8 +212,8 @@ sub event_step { # runs via PublicInbox::DS::requeue
 
 sub DESTROY {
        my ($self) = @_;
+       return if ($PublicInbox::LEI::daemon_pid // -1) != $$;
        my $lei = $self->{lei}; # the original, from lei_up
-       return if $lei->{daemon_pid} != $$;
        my $sock = delete $self->{unref_on_destroy};
        my $s = $lei->{-socks} // [];
        @$s = grep { $_ != $sock } @$s;