in reply to Why this daemon can only receive the HUP signal no more than one time?

Perhaps SIGHUP gets blocked in signal handler and it's stay blocked after exec. Can you check signal mask in the beginning of your script? sigprocmask(2) should be helpful.

  • Comment on Re: Why this daemon can only receive the HUP signal no more than one time?

Replies are listed 'Best First'.
Re^2: Why this daemon can only receive the HUP signal no more than one time?
by sunshine_august (Scribe) on Feb 24, 2009 at 07:26 UTC

    Yes, indeed!

    The daemon will blocked the SIGHUP signal when it execute the SIGHUP handler. And after it relaunch itself in the handler, the SIGHUP remains being blocked, so the SIGHUP sent later is pending.

    Put the following code at the head of the scrpit:

    my $emptySigSet = POSIX::SigSet->new(); my $oldSigSet = POSIX::SigSet->new(); POSIX::sigprocmask( &POSIX::SIG_BLOCK, $emptySigSet, $oldSigSet ); if ( $oldSigSet->ismember( &POSIX::SIGHUP ) ){ print "SIGHUP is blocking.\n"; }else { print "SIGHUP is not blocking.\n"; }

    And replace the old hupMain with the following new one:

    sub hupMain { while (1) { print "Running hup main function.\n"; sleep 3; my $pendingSigSet = POSIX::SigSet->new(); POSIX::sigpending( $pendingSigSet ) ; if ( $pendingSigSet->ismember( &POSIX::SIGHUP ) ){ print "Pending signal set contains SIG_HUP\n"; } } }

    I can observe the SIGHUP signal is being blocking and pending.

        $action=POSIX::SigAction->new('doSigHup',$sigset,&POSIX::SA_NODEFER);
        Note that you are setting up an "unsafe" signal, as opposed to Safe Signal that original poster was using. Furthermore, the use of SA_NODEFER to avoid changes to sigprocmask has the unfortunate side-effect of making your handler re-interruptable from within its own signal handler.

        Altogether, a particularly nasty concoction that may eventually result in data corruption. I'd rather advise to just clear the blocked signal at program (re)start, after the handler is assigned of course.