]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
watch: do not recreate signalfd on SIGHUP
authorEric Wong <e@80x24.org>
Sun, 26 Mar 2023 10:52:46 +0000 (10:52 +0000)
committerEric Wong <e@80x24.org>
Sun, 26 Mar 2023 11:45:58 +0000 (11:45 +0000)
The normal method by which PublicInbox::DS::event_loop sets up
signals once needs some coercing to work with -watch.
Otherwise, we'll end up wasting FDs every time somebody reloads
-watch via SIGHUP.

lib/PublicInbox/Watch.pm
script/public-inbox-watch

index 810fb63b985c0329f40b490607172e1d73747941..693c71818b5bf8e4580b16fe7227d28bbe9005e5 100644 (file)
@@ -528,7 +528,8 @@ sub watch_nntp_init ($$) {
 sub watch { # main entry point
        my ($self, $sig, $oldset) = @_;
        $self->{oldset} = $oldset;
-       $self->{sig} = $sig;
+       my $first_sig;
+       $self->{sig} //= ($first_sig = $sig);
        my $poll = {}; # intvl_seconds => [ uri1, uri2 ]
        watch_imap_init($self, $poll) if $self->{imap};
        watch_nntp_init($self, $poll) if $self->{nntp};
@@ -538,7 +539,7 @@ sub watch { # main entry point
        }
        watch_fs_init($self) if $self->{mdre};
        local @PublicInbox::DS::post_loop_do = (sub { !$self->quit_done });
-       PublicInbox::DS::event_loop($sig, $oldset); # calls ->event_step
+       PublicInbox::DS::event_loop($first_sig, $oldset); # calls ->event_step
        _done_for_now($self);
 }
 
index 4c50461ff4c02950d14d1aa763e0319bd3ee059f..2fb27343d19b56f378cd218ec8d4a3bf7599f785 100755 (executable)
@@ -27,6 +27,7 @@ my $reload = sub {
        $watch->quit;
        $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
        if ($watch) {
+               $watch->{sig} = $prev->{sig}; # prevent redundant signalfd
                warn "# reloaded\n";
        } else {
                warn("E: reloading failed\n");