I want to specify a signal handler in Perl, but using the number, not the name. Is this possible in a succinct way? The lack of symmetry with kill particularly sticks out. For example, instead of
$SIG{USR2} = \&myhandler;
I’d like to say
$SIG{12} = \&myhandler;
The best I have at the moment is to “use Config” and poke around in $Config{sig_name}, based on the code in perldoc perlipc. This is verbose and seems needlessly complicated.
Rationale: I’ve wanted this in two cases recently.
1: I’m being started by a buggy parent process who incorrectly sets signals I care about to ignore, and I want to just reset everything to default. eg http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=679630 The goal would be something simple and brute force like:
foreach my $i (1..32) { $SIG{$i} = 'DEFAULT'; }
2: I’m writing a thin, as-invisible-as-possible wrapper script. If the program I’m wrapping exits with a signal, I want to exit with that same signal. However, I capture a few signals, so I need to clear my own signal handler to ensure i actually exit instead of entering my signal handler. My goal is to write something brief like this:
$ret = system("./other-program");
$SIG{$ret & 127} = 'DEFAULT';
kill $ret & 127, $$;
First question:
Second question:
-or-
-or-
Third question