diff options
author | Eric Wong <e@80x24.org> | 2024-04-01 06:49:38 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2024-04-03 08:28:07 +0000 |
commit | a145f5acf90fff0b146e6e871925950f62fb426a (patch) | |
tree | 493ebdb7d2cb55fdba9b667c47d27f3a253f3d32 /lib/PublicInbox/Daemon.pm | |
parent | 108196adad5e70b6dd40dc431cd1033d44679483 (diff) | |
download | public-inbox-a145f5acf90fff0b146e6e871925950f62fb426a.tar.gz |
There are still some places where on_destroy isn't suitable, This gets rid of getpid() calls in most of those cases to reduce syscall costs and cleanup syscall trace output.
Diffstat (limited to 'lib/PublicInbox/Daemon.pm')
-rw-r--r-- | lib/PublicInbox/Daemon.pm | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 1cc0c9e6..ec76d6b8 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -352,8 +352,7 @@ EOF return unless defined $pid_file; write_pid($pid_file); - # for ->DESTROY: - bless { pid => $$, pid_file => \$pid_file }, __PACKAGE__; + on_destroy \&unlink_pid_file_safe_ish, \$pid_file; } sub has_busy_clients { # post_loop_do CB @@ -476,7 +475,7 @@ sub upgrade { # $_[0] = signal name or number (unused) warn "BUG: .oldbin suffix exists: $pid_file\n"; return; } - unlink_pid_file_safe_ish($$, $pid_file); + unlink_pid_file_safe_ish(\$pid_file); $pid_file .= '.oldbin'; write_pid($pid_file); } @@ -509,23 +508,20 @@ sub upgrade_aborted { my $file = $pid_file; $file =~ s/\.oldbin\z// or die "BUG: no '.oldbin' suffix in $file"; - unlink_pid_file_safe_ish($$, $pid_file); + unlink_pid_file_safe_ish(\$pid_file); $pid_file = $file; eval { write_pid($pid_file) }; warn $@, "\n" if $@; } -sub unlink_pid_file_safe_ish ($$) { - my ($unlink_pid, $file) = @_; - return unless defined $unlink_pid && $unlink_pid == $$; +sub unlink_pid_file_safe_ish ($) { + my ($fref) = @_; - open my $fh, '<', $file or return; + open my $fh, '<', $$fref or return; local $/ = "\n"; defined(my $read_pid = <$fh>) or return; chomp $read_pid; - if ($read_pid == $unlink_pid) { - Net::Server::Daemonize::unlink_pid_file($file); - } + Net::Server::Daemonize::unlink_pid_file($$fref) if $read_pid == $$; } sub master_quit ($) { @@ -696,7 +692,7 @@ sub run { $nworker = 1; local (%XNETD, %POST_ACCEPT); daemon_prepare($default_listen); - my $for_destroy = daemonize(); + my $unlink_on_leave = daemonize(); # localize GCF2C for tests: local $PublicInbox::GitAsyncCat::GCF2C; @@ -706,7 +702,7 @@ sub run { local %POST_ACCEPT; daemon_loop(); - # ->DESTROY runs when $for_destroy goes out-of-scope + # $unlink_on_leave runs } sub write_pid ($) { @@ -715,8 +711,4 @@ sub write_pid ($) { do_chown($path); } -sub DESTROY { - unlink_pid_file_safe_ish($_[0]->{pid}, ${$_[0]->{pid_file}}); -} - 1; |