about summary refs log tree commit homepage
path: root/script/public-inbox-watch
diff options
context:
space:
mode:
Diffstat (limited to 'script/public-inbox-watch')
-rwxr-xr-xscript/public-inbox-watch25
1 files changed, 10 insertions, 15 deletions
diff --git a/script/public-inbox-watch b/script/public-inbox-watch
index 86349d71..9bcd42ed 100755
--- a/script/public-inbox-watch
+++ b/script/public-inbox-watch
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 my $help = <<EOF;
 usage: public-inbox-watch
@@ -11,15 +11,15 @@ use strict;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use IO::Handle; # ->autoflush
 use PublicInbox::Watch;
+use PublicInbox::Import;
+local $PublicInbox::Import::DROP_UNIQUE_UNSUB;
 use PublicInbox::Config;
 use PublicInbox::DS;
-use PublicInbox::Sigfd;
-use PublicInbox::Syscall qw(SFD_NONBLOCK);
 my $do_scan = 1;
 GetOptions('scan!' => \$do_scan, # undocumented, testing only
         'help|h' => \(my $show_help)) or do { print STDERR $help; exit 1 };
 if ($show_help) { print $help; exit 0 };
-my $oldset = PublicInbox::DS::block_signals();
+PublicInbox::DS::block_signals();
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
 local $0 = $0; # local since this script may be eval-ed
@@ -29,7 +29,8 @@ my $reload = sub {
         $watch->quit;
         $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
         if ($watch) {
-                warn("I: reloaded\n");
+                $watch->{sig} = $prev->{sig}; # prevent redundant signalfd
+                warn "# reloaded\n";
         } else {
                 warn("E: reloading failed\n");
                 $watch = $prev;
@@ -39,10 +40,10 @@ my $reload = sub {
 if ($watch) {
         my $scan = sub {
                 return if !$watch;
-                warn "I: scanning\n";
+                warn "# scanning\n";
                 $watch->trigger_scan('full');
         };
-        my $quit = sub {
+        my $quit = sub { # may be called in IMAP/NNTP children
                 $watch->quit if $watch;
                 $watch = undef;
                 $0 .= ' quitting';
@@ -53,15 +54,9 @@ if ($watch) {
                 CHLD => \&PublicInbox::DS::enqueue_reap,
         };
         $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
+        local @SIG{keys %$sig} = values(%$sig); # for non-signalfd/kqueue
 
         # --no-scan is only intended for testing atm, undocumented.
         PublicInbox::DS::requeue($scan) if $do_scan;
-
-        my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
-        local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
-        if (!$sigfd) {
-                PublicInbox::DS::sig_setmask($oldset);
-                PublicInbox::DS->SetLoopTimeout(1000);
-        }
-        $watch->watch($sig, $oldset) while ($watch);
+        $watch->watch($sig) while ($watch);
 }