From: Eric Wong Date: Sat, 24 Jun 2017 00:00:04 +0000 (+0000) Subject: watch: ensure HUP causes the scanner to be reloaded X-Git-Tag: v1.0.0~39 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=5bde05b66f084c7c9dcf7389079aab6925aef328 watch: ensure HUP causes the scanner to be reloaded Otherwise the old watcher may run indefinitely --- diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index c15e1384..f81a917c 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -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 { diff --git a/script/public-inbox-watch b/script/public-inbox-watch index bb655929..a72180c9 100755 --- a/script/public-inbox-watch +++ b/script/public-inbox-watch @@ -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); }