about summary refs log tree commit homepage
path: root/lib/PublicInbox/XapHelper.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-04-26 11:29:43 +0000
committerEric Wong <e@80x24.org>2024-04-28 17:05:32 +0000
commitc807cdd1c2e85237e769532a36819888ca97f8b1 (patch)
tree5832f3904e63020b4c430538fd3abfa2dd4f3825 /lib/PublicInbox/XapHelper.pm
parent5f4c4163ad8d8045dbcfddaeddfdb986a79d4969 (diff)
downloadpublic-inbox-c807cdd1c2e85237e769532a36819888ca97f8b1.tar.gz
When read-only daemons reopen log files via SIGUSR1, be sure to
propagate it to Xapian helper processes to ensure old log files
can be closed and archived.
Diffstat (limited to 'lib/PublicInbox/XapHelper.pm')
-rw-r--r--lib/PublicInbox/XapHelper.pm16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index c55a72ce..746b4d62 100644
--- a/lib/PublicInbox/XapHelper.pm
+++ b/lib/PublicInbox/XapHelper.pm
@@ -200,6 +200,7 @@ sub recv_loop {
         local $SIG{__WARN__} = sub { print $stderr @_ };
         my $rbuf;
         local $SIG{TERM} = sub { undef $in };
+        local $SIG{USR1} = \&reopen_logs;
         while (defined($in)) {
                 PublicInbox::DS::sig_setmask($workerset);
                 my @fds = eval { # we undef $in in SIG{TERM}
@@ -263,6 +264,18 @@ sub do_sigttou {
         }
 }
 
+sub reopen_logs {
+        my $p = $ENV{STDOUT_PATH};
+        defined($p) && open(STDOUT, '>>', $p) and STDOUT->autoflush(1);
+        $p = $ENV{STDERR_PATH};
+        defined($p) && open(STDERR, '>>', $p) and STDERR->autoflush(1);
+}
+
+sub parent_reopen_logs {
+        reopen_logs();
+        kill('USR1', values %WORKERS);
+}
+
 sub xh_alive { $in || scalar(keys %WORKERS) }
 
 sub start (@) {
@@ -276,7 +289,7 @@ sub start (@) {
                 die 'bad args';
         local $workerset = POSIX::SigSet->new;
         $workerset->fillset or die "fillset: $!";
-        for (@PublicInbox::DS::UNBLOCKABLE) {
+        for (@PublicInbox::DS::UNBLOCKABLE, POSIX::SIGUSR1) {
                 $workerset->delset($_) or die "delset($_): $!";
         }
 
@@ -295,6 +308,7 @@ sub start (@) {
                 },
                 TTOU => \&do_sigttou,
                 CHLD => \&PublicInbox::DS::enqueue_reap,
+                USR1 => \&parent_reopen_logs,
         };
         PublicInbox::DS::block_signals();
         start_workers();