about summary refs log tree commit homepage
path: root/lib/PublicInbox/Xapcmd.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-23 09:37:04 +0000
committerEric Wong <e@80x24.org>2019-05-23 17:43:51 +0000
commitbb279f4f305649c99dabdbcc0f45fc42c9be8e7e (patch)
treefe7756773d64797dfb62119c593c00d48d44bcc6 /lib/PublicInbox/Xapcmd.pm
parent4a918d9c17b045ad8151c86b09666799c354908f (diff)
downloadpublic-inbox-bb279f4f305649c99dabdbcc0f45fc42c9be8e7e.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/Xapcmd.pm')
-rw-r--r--lib/PublicInbox/Xapcmd.pm11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index a294d539..999819c7 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;