about summary refs log tree commit homepage
path: root/lib/PublicInbox/DS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-17 23:37:59 +0000
committerEric Wong <e@80x24.org>2023-10-18 20:50:30 +0000
commita4cf3bd57d17577b6dd791d4f0f8e76758d0aafe (patch)
treeb15a6f5d269a9ec0e984d4e5b2cedac5f9388d1a /lib/PublicInbox/DS.pm
parente6e098ab8ebf5eefceee10fc165e192cf6bd8e91 (diff)
downloadpublic-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/DS.pm')
-rw-r--r--lib/PublicInbox/DS.pm12
1 files changed, 12 insertions, 0 deletions
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;