]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import_slrnspool: graceful exit for interruptibility
authorEric Wong <e@80x24.org>
Sun, 11 Jan 2015 23:55:27 +0000 (23:55 +0000)
committerEric Wong <e@80x24.org>
Sun, 11 Jan 2015 23:56:05 +0000 (23:56 +0000)
This should alleviate fears of interrupting the process.

scripts/import_slrnspool

index 1f25eff27f3b39e5b5fd6d5fbbe1d6677fe7cc21..d95836d69c6a8937a9a97bd20d645a05c0c6650f 100755 (executable)
@@ -14,6 +14,10 @@ use PublicInbox::Config;
 use Email::Filter;
 use Email::LocalDelivery;
 sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
+my $exit = 0;
+my $sighandler = sub { $exit = 1 };
+$SIG{INT} = $sighandler;
+$SIG{TERM} = $sighandler;
 my $spool = shift @ARGV or die usage();
 my $recipient = $ENV{ORIGINAL_RECIPIENT};
 defined $recipient or die usage();
@@ -45,7 +49,7 @@ my $ok;
 my $max_gap = 10000;
 my $max = $n + $max_gap;
 
-for (; $n < $max; $n++) {
+for (; $exit == 0 && $n < $max; $n++) {
        my $fn = "$spool/$n";
        print STDERR $fn, "\n";
        open(my $fh, '<', $fn) or next;