From 1c52f49354aa83e71fcceccae888da0c77f2391d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Oct 2021 09:54:41 +0000 Subject: ds: simplify signalfd use Since signalfd is often combined with our event loop, give it a convenient API and reduce the code duplication required to use it. EventLoop is replaced with ::event_loop to allow consistent parameter passing and avoid needlessly passing the package name on stack. We also avoid exporting SFD_NONBLOCK since it's the only flag we support. There's no sense in having the memory overhead of a constant function when it's in cold code. --- lib/PublicInbox/Daemon.pm | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'lib/PublicInbox/Daemon.pm') diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 24dc7791..5be474fa 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -15,7 +15,6 @@ use Socket qw(IPPROTO_TCP SOL_SOCKET); STDOUT->autoflush(1); STDERR->autoflush(1); use PublicInbox::DS qw(now); -use PublicInbox::Syscall qw(SFD_NONBLOCK); require PublicInbox::Listener; use PublicInbox::EOFpipe; use PublicInbox::Sigfd; @@ -513,7 +512,7 @@ EOF }, CHLD => \&reap_children, }; - my $sigfd = PublicInbox::Sigfd->new($sig, 0); + my $sigfd = PublicInbox::Sigfd->new($sig); local @SIG{keys %$sig} = values(%$sig) unless $sigfd; PublicInbox::DS::sig_setmask($oldset) if !$sigfd; while (1) { # main loop @@ -630,20 +629,11 @@ sub daemon_loop ($$$$) { # this calls epoll_create: PublicInbox::Listener->new($_, $tls_cb || $post_accept) } @listeners; - my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); - local @SIG{keys %$sig} = values(%$sig) unless $sigfd; - if (!$sigfd) { - # wake up every second to accept signals if we don't - # have signalfd or IO::KQueue: - PublicInbox::DS::sig_setmask($oldset); - PublicInbox::DS->SetLoopTimeout(1000); - } - PublicInbox::DS->EventLoop; + PublicInbox::DS::event_loop($sig, $oldset); } sub run ($$$;$) { my ($default, $refresh, $post_accept, $tlsd) = @_; - local $SIG{PIPE} = 'IGNORE'; daemon_prepare($default); my $af_default = $default =~ /:8080\z/ ? 'httpready' : undef; my $for_destroy = daemonize(); -- cgit v1.2.3-24-ge0c7