+ my $quit = sub {
+ $watch->quit if $watch;
+ $watch = undef;
+ $0 .= ' quitting';
+ };
+ my $sig = {
+ HUP => $reload,
+ USR1 => $scan,
+ CHLD => \&PublicInbox::DS::enqueue_reap,
+ };
+ $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
+
+ # --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 = (%SIG, %$sig) if !$sigfd;
+ if (!$sigfd) {
+ PublicInbox::Sigfd::set_sigmask($oldset);
+ PublicInbox::DS->SetLoopTimeout(1000);
+ }
+ $watch->watch($sig, $oldset) while ($watch);