-# 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
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;
sub daemon_prepare ($) {
my ($default_listen) = @_;
my $listener_names = {}; # sockname => IO::Handle
- $oldset = PublicInbox::Sigfd::block_signals();
+ $oldset = PublicInbox::DS::block_signals();
@CMD = ($0, @ARGV);
my ($prog) = ($CMD[0] =~ m!([^/]+)\z!g);
my $help = <<EOF;
CHLD => \&reap_children,
};
my $sigfd = PublicInbox::Sigfd->new($sig, 0);
- local %SIG = (%SIG, %$sig) if !$sigfd;
- PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd;
+ local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
+ PublicInbox::DS::sig_setmask($oldset) if !$sigfd;
while (1) { # main loop
my $n = scalar keys %pids;
unless (@listeners) {
}
my $want = $worker_processes - 1;
if ($n <= $want) {
- PublicInbox::Sigfd::block_signals() if !$sigfd;
+ PublicInbox::DS::block_signals() if !$sigfd;
for my $i ($n..$want) {
+ my $seed = rand(0xffffffff);
my $pid = fork;
if (!defined $pid) {
warn "failed to fork worker[$i]: $!\n";
} elsif ($pid == 0) {
+ srand($seed);
+ eval { Net::SSLeay::randomize() };
$set_user->() if $set_user;
return $p0; # run normal work code
} else {
$pids{$pid} = $i;
}
}
- PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd;
+ PublicInbox::DS::sig_setmask($oldset) if !$sigfd;
}
if ($sigfd) { # Linux and IO::KQueue users:
# this calls epoll_create:
PublicInbox::Listener->new($_, $tls_cb || $post_accept)
} @listeners;
- my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK);
- local %SIG = (%SIG, %$sig) if !$sigfd;
+ 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::Sigfd::sig_setmask($oldset);
+ PublicInbox::DS::sig_setmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
}
PublicInbox::DS->EventLoop;