]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watch: ensure HUP causes the scanner to be reloaded
authorEric Wong <e@80x24.org>
Sat, 24 Jun 2017 00:00:04 +0000 (00:00 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Jun 2017 03:07:46 +0000 (03:07 +0000)
Otherwise the old watcher may run indefinitely

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

index c15e138436cd8964e061a40f725212ef425103af..f81a917c5ab74070425a309c3ae3f25a93981fd4 100644 (file)
@@ -179,6 +179,8 @@ sub _try_path {
        $im->add($mime, $self->{spamcheck});
 }
 
+sub quit { $_[0]->{quit} = 1 }
+
 sub watch {
        my ($self) = @_;
        my $cb = sub { _try_fsn_paths($self, \@_) };
@@ -188,7 +190,7 @@ sub watch {
        # in the future...
        require Filesys::Notify::Simple;
        my $watcher = Filesys::Notify::Simple->new($mdir);
-       $watcher->wait($cb) while (1);
+       $watcher->wait($cb) until ($self->{quit});
 }
 
 sub scan {
index bb655929fdbf0050a5f37d4ed622eab759962114..a72180c90b74c89f35315196e237a632953671f0 100755 (executable)
@@ -8,6 +8,7 @@ use PublicInbox::Config;
 my ($config, $watch_md);
 my $reload = sub {
        $config = PublicInbox::Config->new;
+       $watch_md->quit if $watch_md;
        $watch_md = PublicInbox::WatchMaildir->new($config);
 };
 $reload->();
@@ -17,5 +18,5 @@ if ($watch_md) {
        $SIG{USR1} = $scan;
        $SIG{ALRM} = sub { $SIG{ALRM} = 'DEFAULT'; $scan->() };
        alarm(1);
-       $watch_md->watch;
+       $watch_md->watch while ($watch_md);
 }