in reply to Setting signal handlers considered unsafe?
With perl 5.8.8 on CentOS 5.2, exposure of SIG_DFL has something to do with setting a local $SIG{ALRM}.
#!/opt/perl/bin/perl use strict; use warnings; print "set handler 1\n"; $SIG{ALRM} = sub { print "handler 1\n"; }; print "set handler 2\n"; $SIG{ALRM} = sub { print "handler 2\n"; }; print "set handler 3 (local)\n"; { local $SIG{ALRM} = sub { print "handler 3\n"; }; }
produces the following strace output:
write(1, "set handler 1\n", 14set handler 1 ) = 14 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "set handler 2\n", 14set handler 2 ) = 14 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "set handler 3 (local)\n", 22set handler 3 (local) ) = 22 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {SIG_DFL}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 exit_group(0) = ?
Update: It is localizing $SIG{ALRM} that sets the signal handler to SIG_DFL. Presumably a side effect of $SIG{ALRM} being set to undef when it is localized.
#!/opt/perl/bin/perl use strict; use warnings; use Data::Dumper; print "set handler 1\n"; $SIG{ALRM} = sub { print "handler 1\n"; }; print "set handler 2\n"; $SIG{ALRM} = sub { print "handler 2\n"; }; print "set handler 3 (local)\n"; { local $SIG{ALRM}; print "\$SIG{ALRM} is now local: " . Dumper($SIG{ALRM}); $SIG{ALRM} = sub { print "handler 3\n"; }; print "\$SIG{ALRM} is now set locally: " . Dumper($SIG{ALRM}); }
produces:
write(1, "set handler 1\n", 14set handler 1 ) = 14 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "set handler 2\n", 14set handler 2 ) = 14 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "set handler 3 (local)\n", 22set handler 3 (local) ) = 22 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {SIG_DFL}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "$SIG{ALRM} is now local: $VAR1 ="..., 37$SIG{ALRM} is now lo +cal: $VAR1 = ''; ) = 37 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 write(1, "$SIG{ALRM} is now set locally: $"..., 56$SIG{ALRM} is now se +t locally: $VAR1 = sub { "DUMMY" }; ) = 56 rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0 rt_sigaction(SIGALRM, {0x80a3330, [], 0}, {0x80a3330, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 exit_group(0) = ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Setting signal handlers considered unsafe?
by gone2015 (Deacon) on Nov 06, 2008 at 13:54 UTC | |
by ikegami (Patriarch) on Nov 09, 2008 at 18:07 UTC | |
by gone2015 (Deacon) on Nov 09, 2008 at 19:34 UTC | |
by ikegami (Patriarch) on Nov 09, 2008 at 20:03 UTC | |
by gone2015 (Deacon) on Nov 10, 2008 at 00:06 UTC | |
| |
|
Re^2: Setting signal handlers considered unsafe?
by gone2015 (Deacon) on Nov 09, 2008 at 16:59 UTC | |
by ig (Vicar) on Nov 11, 2008 at 11:19 UTC |