]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watch: use "self-inotify-tempfile trick" for quit
authorEric Wong <e@80x24.org>
Sat, 24 Jun 2017 22:26:28 +0000 (22:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Jun 2017 03:44:35 +0000 (03:44 +0000)
This should be more reliable and safer as it'll ensure
existing fast-import instances are shut down properly.

lib/PublicInbox/WatchMaildir.pm
script/public-inbox-watch

index 0e2a6d2c3c5d6f6ea50580b5ad8e25eb9314278f..5e79bb50cc1dc582af2f80d8f683097a3fe9db43 100644 (file)
@@ -201,7 +201,7 @@ sub _try_path {
        $im->add($mime, $self->{spamcheck});
 }
 
-sub quit { $_[0]->{quit} = 1 }
+sub quit { trigger_scan($_[0], 'quit') }
 
 sub watch {
        my ($self) = @_;
@@ -215,7 +215,7 @@ sub watch {
        # in the future...
        require Filesys::Notify::Simple;
        my $fsn = Filesys::Notify::Simple->new([@{$self->{mdir}}, $scandir]);
-       $fsn->wait($cb) until ($self->{quit});
+       $fsn->wait($cb) until $self->{quit};
 }
 
 sub trigger_scan {
@@ -227,6 +227,14 @@ sub trigger_scan {
 
 sub scan {
        my ($self, $path) = @_;
+       if ($path =~ /quit\z/) {
+               %{$self->{opendirs}} = ();
+               _done_for_now($self);
+               $self->{quit} = 1;
+               return;
+       }
+       # else: $path =~ /(cont|full)\z/
+       return if $self->{quit};
        my $max = 10;
        my $opendirs = $self->{opendirs};
        my @dirnames = keys %$opendirs;
index 51f1baa29c98868c6d9ded5c57702540fc1d3a46..0d1cd8319fed5f44a89542ff0aaa27dfc0089385 100755 (executable)
@@ -17,6 +17,10 @@ if ($watch_md) {
        $SIG{HUP} = $reload;
        $SIG{USR1} = $scan;
        $SIG{ALRM} = sub { $SIG{ALRM} = 'DEFAULT'; $scan->() };
+       $SIG{QUIT} = $SIG{TERM} = $SIG{INT} = sub {
+               $watch_md->quit if $watch_md;
+               $watch_md = undef;
+       };
        alarm(1);
        $watch_md->watch while ($watch_md);
 }