/usr/share/perl5/Signal/Mask.pm is in libsignal-mask-perl 0.008-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | package Signal::Mask;
$Signal::Mask::VERSION = '0.008';
use strict;
use warnings FATAL => 'all';
use Config;
use POSIX qw/SIG_BLOCK SIG_UNBLOCK SIG_SETMASK/;
BEGIN {
if (eval { require Thread::SigMask }) {
*sigmask = \&Thread::SigMask::sigmask;
}
else {
require POSIX;
*sigmask = \&POSIX::sigprocmask;
}
}
use IPC::Signal qw/sig_num sig_name/;
use Carp qw/croak/;
my $sig_max = $Config{sig_count} - 1;
tie %Signal::Mask, __PACKAGE__;
sub TIEHASH {
my $class = shift;
my $self = { iterator => 1, };
return bless $self, $class;
}
sub _get_status {
my ($self, $num) = @_;
my $mask = POSIX::SigSet->new;
sigmask(SIG_BLOCK, POSIX::SigSet->new(), $mask);
return $mask->ismember($num);
}
sub FETCH {
my ($self, $key) = @_;
return $self->_get_status(sig_num($key));
}
my $block_signal = sub {
my ($self, $key) = @_;
my $num = sig_num($key);
croak "No such signal '$key'" if not defined $num;
sigmask(SIG_BLOCK, POSIX::SigSet->new($num)) or croak "Couldn't block signal: $!";
return;
};
my $unblock_signal = sub {
my ($self, $key) = @_;
my $num = sig_num($key);
croak "No such signal '$key'" if not defined $num;
my $ret = POSIX::SigSet->new($num);
sigmask(SIG_UNBLOCK, POSIX::SigSet->new($num), $ret) or croak "Couldn't unblock signal: $!";
return $ret->ismember($num);
};
sub STORE {
my ($self, $key, $value) = @_;
my $method = $value ? $block_signal : $unblock_signal;
$self->$method($key);
return;
}
sub DELETE {
my ($self, $key) = @_;
return $self->$unblock_signal($key);
}
sub CLEAR {
my ($self) = @_;
sigmask(SIG_SETMASK, POSIX::SigSet->new());
return;
}
sub EXISTS {
my ($self, $key) = @_;
return defined sig_num($key);
}
sub FIRSTKEY {
my $self = shift;
$self->{iterator} = 1;
return $self->NEXTKEY;
}
sub NEXTKEY {
my $self = shift;
if ($self->{iterator} <= $sig_max) {
my $num = $self->{iterator}++;
return wantarray ? (sig_name($num) => $self->_get_status($num)) : sig_name($num);
}
else {
return;
}
}
sub SCALAR {
my $self = shift;
my $mask = POSIX::SigSet->new;
sigmask(SIG_BLOCK, POSIX::SigSet->new(), $mask);
return scalar grep { $mask->ismember($_) } 1 .. $sig_max;
}
sub UNTIE {
my $self = shift;
$self->CLEAR;
return;
}
sub DESTROY {
}
1; # End of Signal::Mask
# ABSTRACT: Signal masks made easy
__END__
=pod
=encoding UTF-8
=head1 NAME
Signal::Mask - Signal masks made easy
=head1 VERSION
version 0.008
=head1 SYNOPSIS
use Signal::Mask;
{
local $Signal::Mask{INT} = 1;
do_something();
}
#signal delivery gets postponed until now
=head1 DESCRIPTION
Signal::Mask is an abstraction around your process or thread signal mask. It is used to fetch and/or change the signal mask of the calling process or thread. The signal mask is the set of signals whose delivery is currently blocked for the caller. It is available as the global hash %Signal::Mask.
=head1 AUTHOR
Leon Timmermans <fawaka@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|