Apparently not using local is enough to prevent the crashes. sigprocmask also solves the issue and I have been confused about the root cause of my problems.
It looks like the signal handler (essentially calling die) leaked out of the eval { } block. Or doesn't it?
This code:
#!/usr/bin/perl use warnings FATAL => qw( all ); use strict; use Test::More tests => 1; use POSIX qw( _exit ); sub wrap_sigs { my $signals = shift; my $coderef = shift; my $died; my %old_sighandlers; eval { for my $sig (keys %$signals) { $old_sighandlers{$sig} = ($SIG{$sig} || 'DEFAU +LT'); $SIG{$sig} = sub { die ('SIG' . $sig . "\n") +}; } $died = 1 unless eval { $coderef->(); 1 }; for my $sig (keys %old_sighandlers) { $SIG{$sig} = $old_sighandlers{$sig}; } }; return $died; } my $pid = fork; if ($pid) { $SIG{ALRM} = sub { }; my $timeout = time + 5; diag('parent entering wrap_sigs loop'); while (time < $timeout) { wrap_sigs( { ALRM => 1 }, sub { } ); } diag('parent survived, killing child'); kill TERM => $pid; } else { sleep 1; diag('child starting signal storm'); 1 while kill ALRM => getppid; _exit(0); } ok(1, 'survived signal storm');
1..1 # parent entering wrap_sigs loop # child starting signal storm SIGALRM SIGALRM END failed--call queue aborted.
Sorry for shifting the goalposts but have you got any ideas?
In reply to Re^2: Setting signal handlers considered unsafe?
by gnosek
in thread Setting signal handlers considered unsafe?
by gnosek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |