]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watch: stop importers before forking
authorEric Wong <e@yhbt.net>
Sat, 27 Jun 2020 10:03:42 +0000 (10:03 +0000)
committerEric Wong <e@yhbt.net>
Sun, 28 Jun 2020 22:27:19 +0000 (22:27 +0000)
This fixes cases where watch is handling both Maildirs and IMAP
connections.  While we're at it, close open directories in the
IMAP children to save FDs.

lib/PublicInbox/WatchMaildir.pm

index 494fe7a8f212848c00d4480561a0d7ca381a4ce7..249891309790fc117d307f84c319f40d70cffe20 100644 (file)
@@ -465,11 +465,18 @@ sub watch_atfork_child ($) {
        my ($self) = @_;
        delete $self->{idle_pids};
        delete $self->{poll_pids};
+       delete $self->{opendirs};
        PublicInbox::DS->Reset;
        PublicInbox::Sigfd::sig_setmask($self->{oldset});
        %SIG = (%SIG, %{$self->{sig}});
 }
 
+sub watch_atfork_parent ($) {
+       my ($self) = @_;
+       _done_for_now($self);
+       $self->{mics} = {}; # going to be forking, so disconnect
+}
+
 sub imap_idle_reap { # PublicInbox::DS::dwaitpid callback
        my ($self, $pid) = @_;
        my $uri_intvl = delete $self->{idle_pids}->{$pid} or
@@ -501,7 +508,7 @@ sub event_step {
        return if $self->{quit};
        my $idle_todo = $self->{idle_todo};
        if ($idle_todo && @$idle_todo) {
-               $self->{mics} = {}; # going to be forking, so disconnect
+               watch_atfork_parent($self);
                while (my $uri_intvl = shift(@$idle_todo)) {
                        imap_idle_fork($self, $uri_intvl);
                }
@@ -525,7 +532,7 @@ sub watch_imap_fetch_all ($$) {
 sub imap_fetch_fork ($$$) {
        my ($self, $intvl, $uris) = @_;
        return if $self->{quit};
-       $self->{mics} = {}; # going to be forking, so disconnect
+       watch_atfork_parent($self);
        defined(my $pid = fork) or die "fork: $!";
        if ($pid == 0) {
                watch_atfork_child($self);