From a4cf3bd57d17577b6dd791d4f0f8e76758d0aafe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 17 Oct 2023 23:37:59 +0000 Subject: ds: introduce and use do_fork helper This ensures we handle RNG reseeding and resetting the event loop properly in child processes after forking. --- lib/PublicInbox/DS.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index eefbdcc3..9960937d 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -34,6 +34,7 @@ use PublicInbox::Tmpfile; use PublicInbox::Select; use Errno qw(EAGAIN EINVAL ECHILD); use Carp qw(carp croak); +use autodie qw(fork); our @EXPORT_OK = qw(now msg_more awaitpid add_timer add_uniq_timer); my $nextq; # queue for next_tick @@ -737,6 +738,17 @@ sub awaitpid { } } +sub do_fork () { + my $seed = rand(0xffffffff); + my $pid = fork; + if ($pid == 0) { + srand($seed); + eval { Net::SSLeay::randomize() }; + Reset(); + } + $pid; +} + package PublicInbox::DummyPoller; # only used during Reset use v5.12; -- cgit v1.2.3-24-ge0c7