]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Daemon.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / Daemon.pm
index d1a42fc348a4ae4fbd8d4cd32809e7d0a06d1d75..4dcb5fb6f927f416b0e4b2574b7b965535be3637 100644 (file)
@@ -1,7 +1,9 @@
-# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-# contains common daemon code for the httpd, imapd, and nntpd servers.
-# This may be used for read-only IMAP server if we decide to implement it.
+#
+# Contains common daemon code for the httpd, imapd, and nntpd servers
+# and designed for handling thousands of untrusted clients over slow
+# and/or lossy connections.
 package PublicInbox::Daemon;
 use strict;
 use warnings;
@@ -14,7 +16,7 @@ sub SO_ACCEPTFILTER () { 0x1000 }
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
 use PublicInbox::DS qw(now);
-use PublicInbox::Syscall qw($SFD_NONBLOCK);
+use PublicInbox::Syscall qw(SFD_NONBLOCK);
 require PublicInbox::Listener;
 use PublicInbox::EOFpipe;
 use PublicInbox::Sigfd;
@@ -367,14 +369,12 @@ sub inherit ($) {
        foreach my $fd (3..$end) {
                my $s = IO::Handle->new_from_fd($fd, 'r');
                if (my $k = sockname($s)) {
-                       if ($s->blocking) {
-                               $s->blocking(0);
-                               warn <<"";
+                       my $prev_was_blocking = $s->blocking(0);
+                       warn <<"" if $prev_was_blocking;
 Inherited socket (fd=$fd) is blocking, making it non-blocking.
 Set 'NonBlocking = true' in the systemd.service unit to avoid stalled
 processes when multiple service instances start.
 
-                       }
                        $listener_names->{$k} = $s;
                        push @rv, $s;
                } else {
@@ -421,11 +421,8 @@ sub upgrade { # $_[0] = signal name or number (unused)
 }
 
 sub kill_workers ($) {
-       my ($s) = @_;
-
-       while (my ($pid, $id) = each %pids) {
-               kill $s, $pid;
-       }
+       my ($sig) = @_;
+       kill $sig, keys(%pids);
 }
 
 sub upgrade_aborted ($) {
@@ -630,7 +627,7 @@ sub daemon_loop ($$$$) {
                # this calls epoll_create:
                PublicInbox::Listener->new($_, $tls_cb || $post_accept)
        } @listeners;
-       my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK);
+       my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
        local %SIG = (%SIG, %$sig) if !$sigfd;
        if (!$sigfd) {
                # wake up every second to accept signals if we don't