| 1 | package Test2::Util::Sig; | ||||||||||
| 2 | 102 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 102 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 102 | our $VERSION = '1.302226'; | |||||||||
| 6 | |||||||||||
| 7 | 102 | ▶ | use POSIX(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 102 | ▶ | use Test2::Util qw/try IS_WIN32/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 102 | our @EXPORT_OK = qw{ | |||||||||
| 11 | try_sig_mask | ||||||||||
| 12 | }; | ||||||||||
| 13 | 102 | ▶ | BEGIN { require Exporter; our @ISA = qw(Exporter) } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 226 | ▶ | sub try_sig_mask(&) { | ||||||||
|
Subroutine
try_sig_mask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | 226 | my $code = shift; | |||||||||
| 17 | |||||||||||
| 18 | 226 | my ($old, $blocked); | |||||||||
| 19 | 226 | unless(IS_WIN32) { | |||||||||
| 20 | 226 | my $to_block = POSIX::SigSet->new( | |||||||||
| 21 | POSIX::SIGINT(), | ||||||||||
| 22 | POSIX::SIGALRM(), | ||||||||||
| 23 | POSIX::SIGHUP(), | ||||||||||
| 24 | POSIX::SIGTERM(), | ||||||||||
| 25 | POSIX::SIGUSR1(), | ||||||||||
| 26 | POSIX::SIGUSR2(), | ||||||||||
| 27 | ); | ||||||||||
| 28 | 226 | $old = POSIX::SigSet->new; | |||||||||
| 29 | 226 | $blocked = POSIX::sigprocmask(POSIX::SIG_BLOCK(), $to_block, $old); | |||||||||
| 30 | # Silently go on if we failed to log signals, not much we can do. | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 226 | my ($ok, $err) = &try($code); | |||||||||
| 34 | |||||||||||
| 35 | # If our block was successful we want to restore the old mask. | ||||||||||
| 36 | 226 | ▶ | POSIX::sigprocmask(POSIX::SIG_SETMASK(), $old, POSIX::SigSet->new()) if defined $blocked; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 226 | return ($ok, $err); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 102 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||