3 # We assume that TestInit has been used.
22 pass('before the first loop');
30 is($@, "Alarm!\n", 'after the first loop');
32 pass('before the second loop');
41 is($@, "Alarm!\n", 'after the second loop');
44 skip('We can\'t test blocking without sigprocmask', 17)
45 if is_miniperl() || !$Config{d_sigprocmask};
46 skip("This doesn\'t work on $^O threaded builds RT#88814", 17)
47 if ($^O =~ /cygwin/ && $Config{useithreads});
48 skip("This doesn\'t work on $^O version $Config{osvers} RT#88814", 17)
49 if ($^O eq "openbsd" && $Config{osvers} < 5.2);
52 my $pending = POSIX::SigSet->new();
53 is POSIX::sigpending($pending), '0 but true', 'sigpending';
54 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is not pending';
55 my $new = POSIX::SigSet->new(&POSIX::SIGUSR1);
56 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
59 $SIG{USR1} = sub { $gotit++ };
61 is $gotit, 0, 'Haven\'t received third signal yet';
63 diag "2nd sigpending crashes on cygwin" if $^O eq 'cygwin';
64 is POSIX::sigpending($pending), '0 but true', 'sigpending';
65 is $pending->ismember(&POSIX::SIGUSR1), 1, 'SIGUSR1 is pending';
67 my $old = POSIX::SigSet->new();
68 POSIX::sigsuspend($old);
69 is $gotit, 1, 'Received third signal';
70 is POSIX::sigpending($pending), '0 but true', 'sigpending';
71 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is no longer pending';
75 local $SIG{USR1} = sub { die "FAIL\n" };
76 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
77 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is blocked';
78 eval { POSIX::sigsuspend(POSIX::SigSet->new) };
79 is $@, "FAIL\n", 'Exception is thrown, so received fourth signal';
80 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
83 local $::TODO = "Needs investigation" if $^O eq 'VMS';
84 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is still blocked';
88 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
90 is $gotit, 1, 'Haven\'t received fifth signal yet';
91 POSIX::sigprocmask(&POSIX::SIG_UNBLOCK, $new, $old);
92 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 was still blocked';
93 is $gotit, 2, 'Received fifth signal';
95 # test unsafe signal handlers in combination with exceptions
98 # #89718: on old linux kernels, this test hangs. No-ones thought
99 # of a reliable way to probe for this, so for now, just skip the
100 # tests on production releases
101 skip("some OSes hang here", 3) if (int($]*1000) & 1) == 0;
104 skip("Issues on Android", 3) if $^O =~ /android/;
105 my $action = POSIX::SigAction->new(sub { $gotit--, die }, POSIX::SigSet->new, 0);
106 POSIX::sigaction(&POSIX::SIGALRM, $action);
109 my $set = POSIX::SigSet->new;
110 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $set);
111 is $set->ismember(&POSIX::SIGALRM), 0, "SIGALRM is not blocked on attempt $_";
112 POSIX::sigsuspend($set);
114 is $gotit, 0, 'Received both signals';
120 skip("alarm cannot interrupt blocking system calls on $^O", 2)
121 if $^O =~ /MSWin32|cygwin|VMS/;
123 # make sure the signal handler's called in an eval block *before*
126 $SIG{'ALRM'} = sub { die "HANDLER CALLED\n" };
130 select(undef,undef,undef,10);
133 is($@, "HANDLER CALLED\n", 'block eval');
137 select(undef,undef,undef,10);
140 is($@, "HANDLER CALLED\n", 'string eval');
143 eval { $SIG{"__WARN__\0"} = sub { 1 } };
144 like $@, qr/No such hook: __WARN__\\0 at/, q!Fetching %SIG hooks with an extra trailing nul is nul-clean!;
146 eval { $SIG{"__DIE__\0whoops"} = sub { 1 } };
147 like $@, qr/No such hook: __DIE__\\0whoops at/;
152 local $SIG{__WARN__} = sub { $w = shift };
154 $SIG{"KILL\0"} = sub { 1 };
155 like $w, qr/No such signal: SIGKILL\\0 at/, 'Arbitrary signal lookup through %SIG is clean';
161 local $SIG{INT} = sub { $int_called = 1; };
165 # this is needed to ensure signal delivery on MSWin32