Commit a528684d authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Fix up USR2 handling (reopen log file) to maek the child process also

spit to the new file. Turned out to be trickier than I thought it
would be.
parent 6621a67d
......@@ -47,6 +47,7 @@ use POSIX; # for strftime, and sigprocmask and friends
use Fcntl; # file constants for pidfile
use POSIX ":sys_wait_h";
use IO::Poll qw(POLLIN);
use POSIX qw(:errno_h);
# Set up some notification throttling
my $mailgap = 15; # in seconds
......@@ -226,6 +227,7 @@ if ($debug) { qshow(); }
# Gets set if a reload of state from the database should happen.
my $do_reload = 0;
my $do_reopen = 0;
my $sigrestart= 0;
my $sigcleanup= 0;
my $exiting = 0;
......@@ -234,7 +236,7 @@ my $exiting = 0;
# about what would happen if we tried to do this mid-loop. So, we'll
# just set a flag and do it when we're done with our current pass.
$SIG{HUP} = sub { info("SIGHUP - Reloading DB state\n"); $do_reload = 1; };
$SIG{USR2} = sub { info("SIGUSR2 - Reopening logfile\n"); ReOpenLog($LOGFILE); };
$SIG{USR2} = sub { info("SIGUSR2 - Reopening logfile\n"); $do_reopen = 1; };
# Set up other signals.
$SIG{USR1} = \&restart_wrap;
......@@ -281,10 +283,10 @@ sub process_event_queue() {
if ($wait < 0) { debug("Wait was $wait!\n"); $wait=0; }
my $finish = $now + $wait;
while (($event_count != $lastcount || $wait > 0) &&
!($sigrestart || $sigcleanup || $do_reload)) {
!($sigrestart || $sigcleanup || $do_reload || $do_reopen)) {
$lastcount = $event_count;
# Don't block if we got a signal!
if ($wait<=0 || $sigrestart || $sigcleanup || $do_reload) {
if ($wait<=0 || $sigrestart || $sigcleanup || $do_reload || $do_reload){
PollEvents(0, 0);
} else {
#debug("Using blocking event poll - $wait seconds\n");
......@@ -296,7 +298,7 @@ sub process_event_queue() {
#debug("Finished blocking event poll - $wait seconds remain\n");
if ($event_count > 0 &&
(qsize() > 0 || $mailqueue ||
$sigrestart || $sigcleanup || $do_reload)) {
$sigrestart || $sigcleanup || $do_reload || $do_reopen)) {
$blockwait=0;
$wait=0;
#debug("Cancelling wait - timeouts/msgs waiting, or HUP'd\n");
......@@ -347,7 +349,13 @@ while (1) {
if ($sigrestart) { restart(); }
if ($sigcleanup) { cleanup(); }
if ($do_reopen) {
ReOpenLog($LOGFILE);
if (! kill('USR2', $eventchild)) {
fatal("Could not signal(USR2) event reader child\n");
}
$do_reopen = 0;
}
process_event_queue;
}
......@@ -1788,6 +1796,17 @@ sub StartEvents()
# We want to exit on any warning. Let the caller notice.
$SIG{__WARN__} = sub { print STDERR $_[0]; exit(-1); };
# Make sure this child starts writing into the new logfile.
$SIG{USR2} = sub {
print STDERR "Caught a USR2 in child\n";
# Only STDERR can be redirected to the newfile. STDOUT is writing
# to the parent process.
open(STDERR, ">> $LOGFILE") or fatal("reopening $LOGFILE: $!");
select STDERR;
$OUTPUT_AUTOFLUSH = 1;
print STDERR "Opened new logfile in child\n";
};
#
# Just read events and print them to stdout. Parent gets them.
#
......@@ -1806,7 +1825,7 @@ sub StubHandleEvent($$$) {
#
# Print the stuff we care about to stdout for the parent to pick up.
#
print "OBJTYPE='$objtype', OBJNAME='$objname', EVENTTYPE='$eventtype'\n";
print "OBJTYPE='$objtype', OBJNAME='$objname', EVENTTYPE='$eventtype'\n";
if (1) {
print STDERR
"OBJTYPE='$objtype', OBJNAME='$objname', EVENTTYPE='$eventtype'\n";
......@@ -1860,7 +1879,8 @@ sub PollEvents($$)
}
}
elsif ($pollval < 0) {
fatal("Error in nonblocking poll\n");
fatal("Error in nonblocking poll: $!\n")
if ($! != EINTR);
}
return undef;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment