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) = ?

In reply to Re: Setting signal handlers considered unsafe? by ig
in thread Setting signal handlers considered unsafe? by gnosek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.