about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/WatchMaildir.pm4
-rwxr-xr-xscript/public-inbox-watch3
2 files changed, 5 insertions, 2 deletions
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);
 }