3 # We assume that TestInit has been used.
20 pass('before the first loop');
28 is($@, "Alarm!\n", 'after the first loop');
30 pass('before the second loop');
39 is($@, "Alarm!\n", 'after the second loop');
42 skip('We can\'t test blocking without sigprocmask', 17)
43 if is_miniperl() || !$Config{d_sigprocmask};
44 skip('This doesn\'t work on OpenBSD threaded builds RT#88814', 17)
45 if $^O eq 'openbsd' && $Config{useithreads};
48 my $pending = POSIX::SigSet->new();
49 is POSIX::sigpending($pending), '0 but true', 'sigpending';
50 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is not pending';
51 my $new = POSIX::SigSet->new(&POSIX::SIGUSR1);
52 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
55 $SIG{USR1} = sub { $gotit++ };
57 is $gotit, 0, 'Haven\'t received third signal yet';
58 is POSIX::sigpending($pending), '0 but true', 'sigpending';
59 is $pending->ismember(&POSIX::SIGUSR1), 1, 'SIGUSR1 is pending';
61 my $old = POSIX::SigSet->new();
62 POSIX::sigsuspend($old);
63 is $gotit, 1, 'Received third signal';
64 is POSIX::sigpending($pending), '0 but true', 'sigpending';
65 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is no longer pending';
69 local $SIG{USR1} = sub { die "FAIL\n" };
70 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
71 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is blocked';
72 eval { POSIX::sigsuspend(POSIX::SigSet->new) };
73 is $@, "FAIL\n", 'Exception is thrown, so received fourth signal';
74 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
77 local $::TODO = "Needs investigation" if $^O eq 'VMS';
78 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is still blocked';
82 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
84 is $gotit, 1, 'Haven\'t received fifth signal yet';
85 POSIX::sigprocmask(&POSIX::SIG_UNBLOCK, $new, $old);
86 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 was still blocked';
87 is $gotit, 2, 'Received fifth signal';
89 # test unsafe signal handlers in combination with exceptions
90 my $action = POSIX::SigAction->new(sub { $gotit--, die }, POSIX::SigSet->new, 0);
91 POSIX::sigaction(&POSIX::SIGALRM, $action);
94 my $set = POSIX::SigSet->new;
95 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $set);
96 is $set->ismember(&POSIX::SIGALRM), 0, "SIGALRM is not blocked on attempt $_";
97 POSIX::sigsuspend($set);
99 is $gotit, 0, 'Received both signals';
103 skip("alarm cannot interrupt blocking system calls on $^O", 2)
104 if ($^O eq 'MSWin32' || $^O eq 'VMS');
106 # make sure the signal handler's called in an eval block *before*
109 $SIG{'ALRM'} = sub { die "HANDLER CALLED\n" };
113 select(undef,undef,undef,10);
116 is($@, "HANDLER CALLED\n", 'block eval');
120 select(undef,undef,undef,10);
123 is($@, "HANDLER CALLED\n", 'string eval');
126 eval { $SIG{"__WARN__\0"} = sub { 1 } };
127 like $@, qr/No such hook: __WARN__\\0 at/, q!Fetching %SIG hooks with an extra trailing nul is nul-clean!;
129 eval { $SIG{"__DIE__\0whoops"} = sub { 1 } };
130 like $@, qr/No such hook: __DIE__\\0whoops at/;
135 local $SIG{__WARN__} = sub { $w = shift };
137 $SIG{"KILL\0"} = sub { 1 };
138 like $w, qr/No such signal: SIGKILL\\0 at/, 'Arbitrary signal lookup through %SIG is clean';