]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
watch: close inotify FD on ->quit
authorEric Wong <e@80x24.org>
Thu, 6 Apr 2023 12:39:53 +0000 (12:39 +0000)
committerEric Wong <e@80x24.org>
Thu, 6 Apr 2023 21:20:51 +0000 (21:20 +0000)
For simplicity, we quit and recreate an entire watch instance
on SIGHUP.  However, inotify (and signalfd) FDs are tied to
the DS event loop and stay pinned to existence that way.
Thus we explicitly close the FD in Watch->quit to prevent
leakage on SIGHUP.

lib/PublicInbox/Watch.pm

index b87abafed22bc798b29fee782d2a3e4ebc91f60d..c7acda14a804c1315ad24b8fdda3f0663188f385 100644 (file)
@@ -256,6 +256,10 @@ sub quit {
        %{$self->{opendirs}} = ();
        _done_for_now($self);
        quit_done($self);
+       if (defined(my $fd = delete $self->{dir_idle_fd})) {
+               my $di = $PublicInbox::DS::DescriptorMap{$fd};
+               $di->close if $di && $di->can('add_watches');
+       }
        if (my $idle_mic = delete $self->{idle_mic}) {
                return unless $idle_mic->IsConnected && $idle_mic->Socket;
                eval { $idle_mic->done };
@@ -280,6 +284,7 @@ sub watch_fs_init ($) {
        require PublicInbox::DirIdle;
        # inotify_create + EPOLL_CTL_ADD
        my $dir_idle = PublicInbox::DirIdle->new($cb);
+       $self->{dir_idle_fd} = fileno($dir_idle->{sock}) if $dir_idle->{sock};
        $dir_idle->add_watches([keys %{$self->{mdmap}}]);
 }