From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D333D20831 for ; Mon, 26 Jun 2017 03:15:45 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] watch: ensure HUP causes the scanner to be reloaded Date: Mon, 26 Jun 2017 03:15:41 +0000 Message-Id: <20170626031545.11879-2-e@80x24.org> In-Reply-To: <20170626031545.11879-1-e@80x24.org> References: <20170626031545.11879-1-e@80x24.org> List-Id: Otherwise the old watcher may run indefinitely --- lib/PublicInbox/WatchMaildir.pm | 4 +++- script/public-inbox-watch | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index c15e138..f81a917 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 bb65592..a72180c 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); } -- EW