From 36711d6bdf8a767177e0f2f305723354121f8327 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 24 Sep 2015 03:37:21 +0000 Subject: [PATCH] nntpd: support SIGUSR2 in single-process mode, too We may support SIGUSR2 in single-process mode as long as permissions aren't wonky. --- public-inbox-nntpd | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/public-inbox-nntpd b/public-inbox-nntpd index 9fb69cec..67fc90b2 100644 --- a/public-inbox-nntpd +++ b/public-inbox-nntpd @@ -99,6 +99,9 @@ if (defined $pid_file || defined $group || defined $user || $daemonize) { if (defined $pid_file) { my $unlink_pid = $$; Net::Server::Daemonize::create_pid_file($pid_file); + if ($uid and !chown($uid, $gid, $pid_file)) { + warn "could not chown $pid_file: $!\n"; + } END { unlink_pid_file_safe_ish($unlink_pid, $pid_file) }; } } @@ -175,14 +178,15 @@ if ($worker_processes > 0) { sysread($r, my $buf, 8); } } else { + $set_user->() if $set_user; + $SIG{USR2} = sub { worker_quit() if upgrade() }; worker: # this calls epoll_create: - @listeners = map { PublicInbox::Listener->new($_) } @listeners; reopen_logs(); $SIG{QUIT} = $SIG{INT} = $SIG{TERM} = *worker_quit; $SIG{USR1} = *reopen_logs; $SIG{HUP} = $refresh; - $_->watch_read(1) for @listeners; + PublicInbox::Listener->new($_) for @listeners; Danga::Socket->EventLoop; } @@ -192,7 +196,6 @@ sub worker_quit { # killing again terminates immediately: exit unless @listeners; - $_->close for @listeners; @listeners = (); # give slow clients 30s to finish reading/writing whatever @@ -372,7 +375,9 @@ sub new ($$) { listen($s, 1024); IO::Handle::blocking($s, 0); my $self = fields::new($class); - $self->SUPER::new($s); + $self->SUPER::new($s); # calls epoll_create for the first socket + $self->watch_read(1); + $self } sub event_read { -- 2.44.0