This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove Configure code that supported the old-style nested layout for ext/
[perl5.git] / lib / sigtrap.pm
index 378ca89..df728c8 100644 (file)
@@ -8,7 +8,7 @@ sigtrap - Perl pragma to enable simple signal handling
 
 use Carp;
 
-$VERSION = 1.01;
+$VERSION = 1.07;
 $Verbose ||= 0;
 
 sub import {
@@ -29,13 +29,16 @@ sub import {
            }
        }
        elsif ($_ eq 'normal-signals') {
-           unshift @_, qw(HUP INT PIPE TERM);
+           unshift @_, grep(exists $SIG{$_}, qw(HUP INT PIPE TERM));
        }
        elsif ($_ eq 'error-signals') {
-           unshift @_, qw(ABRT BUS EMT FPE ILL QUIT SEGV SYS TRAP);
+           unshift @_, grep(exists $SIG{$_},
+                            qw(ABRT BUS EMT FPE ILL QUIT SEGV SYS TRAP));
        }
        elsif ($_ eq 'old-interface-signals') {
-           unshift @_, qw(ABRT BUS EMT FPE ILL PIPE QUIT SEGV SYS TERM TRAP);
+           unshift @_,
+           grep(exists $SIG{$_},
+                qw(ABRT BUS EMT FPE ILL PIPE QUIT SEGV SYS TERM TRAP));
        }
        elsif ($_ eq 'stack-trace') {
            $handler = \&handler_traceback;
@@ -92,8 +95,7 @@ sub handler_traceback {
     # Now go for broke.
     for ($i = 1; ($p,$f,$l,$s,$h,$w,$e,$r) = caller($i); $i++) {
         @a = ();
-       for $arg (@args) {
-           $_ = "$arg";
+       for (@{[@args]}) {
            s/([\'\\])/\\$1/g;
            s/([^\0]*)/'$1'/
              unless /^(?: -?[\d.]+ | \*[\w:]* )$/x;
@@ -112,7 +114,7 @@ sub handler_traceback {
        } elsif ($s eq '(eval)') {
            $s = "eval {...}";
        }
-       $f = "file `$f'" unless $f eq '-e';
+       $f = "file '$f'" unless $f eq '-e';
        $mess = "$w$s$a called from $f line $l\n";
        syswrite(STDERR, $mess, length($mess));
     }
@@ -164,9 +166,9 @@ installed signals.
 
 =item B<stack-trace>
 
-The handler used for subsequently installed signals will output a Perl
-stack trace to STDERR and then tries to dump core.  This is the default
-signal handler.
+The handler used for subsequently installed signals outputs a Perl stack
+trace to STDERR and then tries to dump core.  This is the default signal
+handler.
 
 =item B<die>
 
@@ -177,13 +179,14 @@ The handler used for subsequently installed signals calls C<die>
 
 I<your-handler> will be used as the handler for subsequently installed
 signals.  I<your-handler> can be any value which is valid as an
-assignment to an element of C<%SIG>.
+assignment to an element of C<%SIG>. See L<perlvar> for examples of
+handler functions.
 
 =back
 
 =head2 SIGNAL LISTS
 
-B<sigtrap> has two built-in lists of signals to trap.  They are:
+B<sigtrap> has a few built-in lists of signals to trap.  They are:
 
 =over 4
 
@@ -204,17 +207,22 @@ QUIT, SEGV, SYS and TRAP.
 These are the signals which were trapped by default by the old
 B<sigtrap> interface, they are ABRT, BUS, EMT, FPE, ILL, PIPE, QUIT,
 SEGV, SYS, TERM, and TRAP.  If no signals or signals lists are passed to
-B<sigtrap> this list is used.
+B<sigtrap>, this list is used.
 
 =back
 
+For each of these three lists, the collection of signals set to be
+trapped is checked before trapping; if your architecture does not
+implement a particular signal, it will not be trapped but rather
+silently ignored.
+
 =head2 OTHER
 
 =over 4
 
 =item B<untrapped>
 
-This token tells B<sigtrap> only to install handlers for subsequently
+This token tells B<sigtrap> to install handlers only for subsequently
 listed signals which aren't already trapped or ignored.
 
 =item B<any>
@@ -224,9 +232,9 @@ listed signals.  This is the default behavior.
 
 =item I<signal>
 
-Any argument which looks like a signals name (that is,
-C</^[A-Z][A-Z0-9]*$/>) is taken as a signal name and indicates that
-B<sigtrap> should install a handler for it.
+Any argument which looks like a signal name (that is,
+C</^[A-Z][A-Z0-9]*$/>) indicates that B<sigtrap> should install a
+handler for that name.
 
 =item I<number>