diff --git a/pod/perlipc.pod b/pod/perlipc.pod index db1fe3df723c1..aa19ed90c8684 100644 --- a/pod/perlipc.pod +++ b/pod/perlipc.pod @@ -183,6 +183,12 @@ the process. Many daemons provide this mechanism using a C signal handler. When you want to tell the daemon to reread the file, simply send it the C signal. +Not all platforms automatically reinstall their (native) signal +handlers after a signal delivery. This means that the handler works +the first time the signal is sent, only. The solution to this problem +is to use C signal handlers if available; their behavior +is well-defined. + The following example implements a simple daemon, which restarts itself every time the C signal is received. The actual code is located in the subroutine C, which just prints some debugging @@ -205,10 +211,16 @@ info to show that it works; it should be replaced with the real code. my $SELF = catfile($FindBin::Bin, $script); # POSIX unmasks the sigprocmask properly - $SIG{HUP} = sub { + 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) || die "$0: couldn't restart: $!"; - }; + } code();