]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ipc: remove {-ipc_pid} field
authorEric Wong <e@80x24.org>
Fri, 29 Aug 2025 20:38:54 +0000 (20:38 +0000)
committerEric Wong <e@80x24.org>
Mon, 1 Sep 2025 18:35:47 +0000 (18:35 +0000)
The fork generation is already attached to the response pipe,
so there's no need to keep the PID around and do comparisons
against the getpid(2) result.

lib/PublicInbox/IPC.pm

index db313104dda5ebb6d5d8bb97582cf9b0e4921ffc..98cbd5139d6fe8820ef0e137fe0113ed17181c46 100644 (file)
@@ -101,7 +101,7 @@ sub exit_exception { exit(!!$@) }
 sub ipc_worker_spawn {
        my ($self, $ident, $oldset, $fields, @cb_args) = @_;
        return if $self->{-ipc_res} && $self->{-ipc_res}->can_reap; # idempotent
-       delete(@$self{qw(-ipc_req -ipc_res -ipc_pid)});
+       delete(@$self{qw(-ipc_req -ipc_res)});
        pipe(my $r_req, my $w_req);
        pipe(my $r_res, my $w_res);
        my $sigset = $oldset // PublicInbox::DS::block_signals();
@@ -132,7 +132,7 @@ sub ipc_worker_spawn {
        $self->{-ipc_req} = $w_req;
        $self->{-ipc_res} = PublicInbox::IO::attach_pid($r_res, $pid,
                                        \&ipc_worker_reap, $self, @cb_args);
-       $self->{-ipc_pid} = $pid;
+       $pid; # used by tests
 }
 
 sub ipc_worker_reap { # awaitpid callback
@@ -159,15 +159,7 @@ sub ipc_atfork_child {
 # idempotent, can be called regardless of whether worker is active or not
 sub ipc_worker_stop {
        my ($self) = @_;
-       my $pid = delete $self->{-ipc_pid};
-       my ($w_req, $r_res) = delete(@$self{qw(-ipc_req -ipc_res)});
-       if (!$w_req && !$r_res) {
-               die "unexpected PID:$pid without IPC pipes" if $pid;
-               return; # idempotent
-       }
-       die 'no PID with IPC pipes' unless $pid;
-       $w_req = undef; # order matters
-       $r_res = undef;
+       delete $self->{$_} for qw(-ipc_req -ipc_res); # order matters
 }
 
 sub _wait_return ($$) {
@@ -197,9 +189,9 @@ sub ipc_do {
 # causes newer siblings to inherit older siblings sockets
 sub ipc_sibling_atfork_child {
        my ($self) = @_;
-       my $pid = delete $self->{-ipc_pid};
-       delete(@$self{qw(-ipc_req -ipc_res)});
-       $pid == $$ and die "BUG: $$ ipc_atfork_child called on itself";
+       my (undef, $res) = delete(@$self{qw(-ipc_req -ipc_res)});
+       $res && $res->can_reap and
+               die "BUG: $$ ipc_atfork_child called on itself";
 }
 
 sub recv_and_run {