about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-09 10:09:35 +0000
committerEric Wong <e@80x24.org>2023-11-09 21:53:47 +0000
commit45edb4b5e13c5f030e776577045386f11c797c6c (patch)
tree8d867c2c1822b0ae687786e3755b3056199f91fd
parentc8a229eca341949ff37c4958f7c75a9cea3a990d (diff)
downloadpublic-inbox-45edb4b5e13c5f030e776577045386f11c797c6c.tar.gz
->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.
-rw-r--r--lib/PublicInbox/LEI.pm2
-rw-r--r--lib/PublicInbox/LeiUp.pm4
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 2832db63..f32e5bbc 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -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) = @_;
diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index cd2337b4..0faa180d 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -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;