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();
14 my ($config, $watch_md);
16 $config = PublicInbox::Config->new;
17 $watch_md->quit if $watch_md;
18 $watch_md = PublicInbox::WatchMaildir->new($config);
22 my $scan = sub { $watch_md->trigger_scan('full') if $watch_md };
24 $watch_md->quit if $watch_md;
30 CHLD => \&PublicInbox::DS::enqueue_reap,
32 $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
34 # --no-scan is only intended for testing atm, undocumented.
35 unless (grep(/\A--no-scan\z/, @ARGV)) {
36 PublicInbox::DS::requeue($scan);
38 my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK);
39 local %SIG = (%SIG, %$sig) if !$sigfd;
41 PublicInbox::Sigfd::set_sigmask($oldset);
42 PublicInbox::DS->SetLoopTimeout(1000);
44 $watch_md->watch($sig, $oldset) while ($watch_md);