2 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::WatchMaildir;
7 use PublicInbox::Config;
9 use PublicInbox::Sigfd;
10 use PublicInbox::Syscall qw(SFD_NONBLOCK);
11 my $oldset = PublicInbox::Sigfd::block_signals();
12 my ($config, $watch_md);
14 $config = PublicInbox::Config->new;
15 $watch_md->quit if $watch_md;
16 $watch_md = PublicInbox::WatchMaildir->new($config);
20 my $scan = sub { $watch_md->trigger_scan('full') if $watch_md };
22 $watch_md->quit if $watch_md;
28 CHLD => \&PublicInbox::DS::enqueue_reap,
30 $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
32 # --no-scan is only intended for testing atm, undocumented.
33 unless (grep(/\A--no-scan\z/, @ARGV)) {
34 PublicInbox::DS::requeue($scan);
36 my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
37 local %SIG = (%SIG, %$sig) if !$sigfd;
39 PublicInbox::Sigfd::set_sigmask($oldset);
40 PublicInbox::DS->SetLoopTimeout(1000);
42 $watch_md->watch($sig, $oldset) while ($watch_md);