in reply to Re^2: Why this daemon can only receive the HUP signal no more than one time?
in thread Why this daemon can only receive the HUP signal no more than one time?

That's correct. First (FWIW) I can confirm your observation (SuSE 11.1, 2.6.27.7-9-pae, perl 5.10.0).

The problem seems to be that your daemon exec's from within the signal-handler (presumably inheriting a blocked signal mask). After applying a quick and dirty work-around, the program reloaded as expected multiple times. The work-around was to set a global variable $PLEASE_RELOAD=1; (initialised to 0) within the HUP-handler and to incorporate something like relaunch( $runDir, $pidFile, $exeFile ) if $PLEASE_RELOAD; into hupMain() allowing to exec outside the HUP signal handler.

This is ugly, but it seems to locate the problem somewhere near the HUP handler...
Another hint: you used a variable called $parentPid to save the children/daemons PID.

Update: Maybe this snipped from perlipc provides a useful hint?

# POSIX unmasks the sigprocmask properly my $sigset = POSIX::SigSet->new(); my $action = POSIX::SigAction->new('sigHUP_handler', $sigset, &POSIX::SA_NODEFER); POSIX::sigaction(&POSIX::SIGHUP, $action); sub sigHUP_handler { print "got SIGHUP\n"; exec($SELF, @ARGV) or die "Couldn't restart: $!\n"; }
Update: Hm, forget to note: SIGHUPSIGTERM (Argl. Sorry, confused that, AM is right, see below.) is send by the OS on shutdown (usually followed by SIGKILL a little bit later) - this would relaunch your daemon during shutdown. Maybe it is a better idea to use SIGUSR1 to reload the daemon?

Replies are listed 'Best First'.
Re^4: Why this daemon can only receive the HUP signal no more than one time?
by Anonymous Monk on Feb 24, 2009 at 15:06 UTC
    the OS doesn't send SIGHUP on shutdown. Many daemons use SIGHUP for reloading config. The OS on shutdown will send SIGTERM and then follow with SIGKILL if needed.