I'm not sure if this is a question or a meditation really.

I asked a recent question about a problem with open3(). It turned out that the problem was really with my use of local signal handlers.

The following code works with 5.10.1 but not with 5.14.2:

#!/usr/bin/perl use strict; use warnings; print "starting pid=$$\n"; my $I = 0; { my $pid = 0; sub handler { my $sig = shift; $I += 1; print "caught $sig\n"; local $SIG{$sig} = 'IGNORE'; # doesn't work with local!! kill($sig, -$$); print "end of handler\n"; } local $SIG{INT} = \&handler; kill('INT', $$); } print "ending I=$I\n";

With 5.10.1, it calls handler() twice and then exits with I=2; with 5.14.2 it calls the handler many times before crashing with a segfault.

Removing the local from the inner $SIG{$sig} allows it to work with 5.14.2, which makes sense if I'm right in thinking that that command changes the immediately-containing signal handler, and not the global one.

So my question is: Since this can break existing (poorly written) code, is this a known effect, and if so, is it documented?

cheers

Chris


In reply to Signals in 5.14 vs 5.10 by ChrisDennis

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.