diff options
author | Eric Wong <e@80x24.org> | 2023-10-17 23:37:59 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-18 20:50:30 +0000 |
commit | a4cf3bd57d17577b6dd791d4f0f8e76758d0aafe (patch) | |
tree | b15a6f5d269a9ec0e984d4e5b2cedac5f9388d1a /lib/PublicInbox/Daemon.pm | |
parent | e6e098ab8ebf5eefceee10fc165e192cf6bd8e91 (diff) | |
download | public-inbox-a4cf3bd57d17577b6dd791d4f0f8e76758d0aafe.tar.gz |
This ensures we handle RNG reseeding and resetting the event loop properly in child processes after forking.
Diffstat (limited to 'lib/PublicInbox/Daemon.pm')
-rw-r--r-- | lib/PublicInbox/Daemon.pm | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 520cef72..f33f6f17 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -541,17 +541,11 @@ sub reap_worker { # awaitpid CB sub start_worker ($) { my ($nr) = @_; - my $seed = rand(0xffffffff); return unless @listeners; - my $pid = fork; - if (!defined($pid)) { - warn "fork: $!"; - } elsif ($pid == 0) { + my $pid = PublicInbox::DS::do_fork; + if ($pid == 0) { undef %WORKERS; - PublicInbox::DS::Reset(); local $PublicInbox::DS::Poller; # allow epoll/kqueue - srand($seed); - eval { Net::SSLeay::randomize() }; $set_user->() if $set_user; PublicInbox::EOFpipe->new($parent_pipe, \&worker_quit); worker_loop(); @@ -563,9 +557,9 @@ sub start_worker ($) { } sub start_workers { - for my $nr (grep { !defined($WORKERS{$_}) } (0..($nworker - 1))) { - start_worker($nr); - } + my @idx = grep { !defined($WORKERS{$_}) } (0..($nworker - 1)) or return; + eval { start_worker($_) for @idx }; + warn "E: $@\n" if $@; } sub trim_workers { |