From 0d6777e0389fe2db3edce41d675320746433f5b7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 31 Dec 2020 13:51:54 +0000 Subject: on_destroy: support PID owner guard Since we'll be forking for Xapian indexing and maybe other places, having a simple guard in place to ensure OnDestroy doesn't unexpectedly unlink files or similar is a safer option. --- lib/PublicInbox/LEI.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/LEI.pm') diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index b84e24ef..4af85d49 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -745,9 +745,8 @@ sub lazy_start { # reading the <$daemon> pipe. openlog($path, 'pid', 'user'); local $SIG{__WARN__} = sub { syslog('warning', "@_") }; - my $owner_pid = $$; - my $on_destroy = PublicInbox::OnDestroy->new(sub { - syslog('crit', "$@") if $@ && $$ == $owner_pid; + my $on_destroy = PublicInbox::OnDestroy->new($$, sub { + syslog('crit', "$@") if $@; }); open STDERR, '>&STDIN' or die "redirect stderr failed: $!"; open STDOUT, '>&STDIN' or die "redirect stdout failed: $!"; -- cgit v1.2.3-24-ge0c7