This behaviour is all quite predictable given that SIGALRM is sometimes set to SIG_DFL.
Yes, naturally.
The question is, why is SIGALRM being set to SIG_DFL then back to perl's signal handler each time the local %SIG is set?
Thank you for your detailed analysis. This agrees with my observation that local $SIG{...} increases the chance of "something breaking".
The following code doesn't die immediately and doesn't set the handler to SIG_DFL anywhere (except once during what looks like early startup). I'm sure I have already tried it, but everybody makes mistakes :) I'll give it a more intensive test tomorrow.
#!/usr/bin/perl use warnings FATAL => qw( all ); use strict; use POSIX qw( :signal_h ); $SIG{ALRM} = sub { print "SIGARLM: main handler\n" }; sub f { my $sigset = POSIX::SigSet->new; my $blockset = POSIX::SigSet->new( SIGALRM ); sigprocmask(SIG_BLOCK, $blockset, $sigset ); $SIG{ALRM} = sub { print "SIGARLM\n" }; sigprocmask(SIG_SETMASK, $sigset ); # do something useful here sigprocmask(SIG_BLOCK, $blockset, $sigset ); $SIG{ALRM} = sub { print "SIGARLM: main handler\n" }; sigprocmask(SIG_SETMASK, $sigset ); } if (fork) { # parent f while 1; } else { # child sleep 1; print "child starting\n"; 1 while kill ALRM => getppid; }
In reply to Re^2: Setting signal handlers considered unsafe?
by gnosek
in thread Setting signal handlers considered unsafe?
by gnosek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |