X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWatch.pm;h=3f6fe21b726f30d3d185032e45ca7e20d358a561;hb=950485f0da0b79832e7ef100ac419f40c8bd30e0;hp=387eb6d252e9a0f329b1fcbaef0ec81a8020a70e;hpb=207f0f93632e26818f2ed3b9d78bf3251b5a69b3;p=public-inbox.git diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index 387eb6d2..3f6fe21b 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -12,7 +12,6 @@ use PublicInbox::MdirReader; use PublicInbox::NetReader; use PublicInbox::Filter::Base qw(REJECT); use PublicInbox::Spamcheck; -use PublicInbox::Sigfd; use PublicInbox::DS qw(now add_timer); use PublicInbox::MID qw(mids); use PublicInbox::ContentHash qw(content_hash); @@ -283,7 +282,8 @@ sub watch_fs_init ($) { }; require PublicInbox::DirIdle; # inotify_create + EPOLL_CTL_ADD - PublicInbox::DirIdle->new([keys %{$self->{mdmap}}], $cb); + my $dir_idle = PublicInbox::DirIdle->new($cb); + $dir_idle->add_watches([keys %{$self->{mdmap}}]); } sub net_cb { # NetReader::(nntp|imap)_each callback @@ -330,6 +330,7 @@ sub imap_idle_once ($$$$) { my $end = now() + $intvl; warn "I: $uri idling for ${intvl}s\n"; local $0 = "IDLE $0"; + return if $self->{quit}; unless ($mic->idle) { return if $self->{quit}; return "E: IDLE failed on $uri: $!"; @@ -384,15 +385,13 @@ sub watch_atfork_child ($) { delete $self->{poll_pids}; delete $self->{opendirs}; PublicInbox::DS->Reset; - %SIG = (%SIG, %{$self->{sig}}, CHLD => 'DEFAULT'); + my $sig = delete $self->{sig}; + $sig->{CHLD} = 'DEFAULT'; + @SIG{keys %$sig} = values %$sig; PublicInbox::DS::sig_setmask($self->{oldset}); } -sub watch_atfork_parent ($) { - my ($self) = @_; - _done_for_now($self); - PublicInbox::DS::block_signals(); -} +sub watch_atfork_parent ($) { _done_for_now($_[0]) } sub imap_idle_requeue { # DS::add_timer callback my ($self, $uri_intvl) = @_; @@ -446,13 +445,12 @@ sub event_step { return if $self->{quit}; my $idle_todo = $self->{idle_todo}; if ($idle_todo && @$idle_todo) { - my $oldset = watch_atfork_parent($self); + watch_atfork_parent($self); eval { while (my $uri_intvl = shift(@$idle_todo)) { imap_idle_fork($self, $uri_intvl); } }; - PublicInbox::DS::sig_setmask($oldset); die $@ if $@; } fs_scan_step($self) if $self->{mdre}; @@ -489,7 +487,7 @@ sub poll_fetch_fork { # DS::add_timer callback my ($self, $intvl, $uris) = @_; return if $self->{quit}; pipe(my ($r, $w)) or die "pipe: $!"; - my $oldset = watch_atfork_parent($self); + watch_atfork_parent($self); my $seed = rand(0xffffffff); my $pid = fork; if (defined($pid) && $pid == 0) { @@ -505,7 +503,6 @@ sub poll_fetch_fork { # DS::add_timer callback close $w; _exit(0); } - PublicInbox::DS::sig_setmask($oldset); die "fork: $!" unless defined $pid; $self->{poll_pids}->{$pid} = [ $intvl, $uris ]; PublicInbox::EOFpipe->new($r, \&reap, [$pid, \&poll_fetch_reap, $self]); @@ -568,7 +565,7 @@ sub watch { # main entry point } watch_fs_init($self) if $self->{mdre}; PublicInbox::DS->SetPostLoopCallback(sub { !$self->quit_done }); - PublicInbox::DS->EventLoop; # calls ->event_step + PublicInbox::DS::event_loop($sig, $oldset); # calls ->event_step _done_for_now($self); }