From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3B13E2067E for ; Thu, 23 May 2019 09:37:15 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 26/26] xapcmd: do not reset %SIG until last Xtmpdir is done Date: Thu, 23 May 2019 09:37:04 +0000 Message-Id: <20190523093704.18367-27-e@80x24.org> In-Reply-To: <20190523093704.18367-1-e@80x24.org> References: <20190523093704.18367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: To properly handle compact tmpdir cleanup in single process situations, we need to carefully account for Xtmpdir not being a singleton and ensuring we don't clobber signal handlers which belong to other Xtmpdirs. --- lib/PublicInbox/Xapcmd.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index a294d53..999819c 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -22,6 +22,8 @@ sub commit_changes ($$$) { my $im = $ibx->importer(0); $im->lock_acquire if !$opt->{-coarse_lock}; + $SIG{INT} or die 'BUG: $SIG{INT} not handled'; + while (my ($old, $new) = each %$tmp) { my @st = stat($old) or die "failed to stat($old): $!\n"; @@ -346,7 +348,12 @@ sub new { sub done { my ($self) = @_; delete $owner{"$self"}; - $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT'; + + my %known_pids; + $known_pids{$_}++ foreach values %owner; + if (!$known_pids{$$}) { + $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT'; + } %$self = (); } @@ -357,7 +364,7 @@ sub DESTROY { foreach my $new (values %$self) { remove_tree($new) unless -d "$new/old"; } - $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = 'DEFAULT'; + done($self); } 1; -- EW