3 # We assume that TestInit has been used.
21 pass('before the first loop');
29 is($@, "Alarm!\n", 'after the first loop');
31 pass('before the second loop');
40 is($@, "Alarm!\n", 'after the second loop');
43 skip('We can\'t test blocking without sigprocmask', 17)
44 if is_miniperl() || !$Config{d_sigprocmask};
45 skip('This doesn\'t work on $^O threaded builds RT#88814', 17)
46 if $^O =~ /openbsd|cygwin/ && $Config{useithreads};
49 my $pending = POSIX::SigSet->new();
50 is POSIX::sigpending($pending), '0 but true', 'sigpending';
51 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is not pending';
52 my $new = POSIX::SigSet->new(&POSIX::SIGUSR1);
53 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
56 $SIG{USR1} = sub { $gotit++ };
58 is $gotit, 0, 'Haven\'t received third signal yet';
60 diag "2nd sigpending crashes on cygwin" if $^O eq 'cygwin';
61 is POSIX::sigpending($pending), '0 but true', 'sigpending';
62 is $pending->ismember(&POSIX::SIGUSR1), 1, 'SIGUSR1 is pending';
64 my $old = POSIX::SigSet->new();
65 POSIX::sigsuspend($old);
66 is $gotit, 1, 'Received third signal';
67 is POSIX::sigpending($pending), '0 but true', 'sigpending';
68 is $pending->ismember(&POSIX::SIGUSR1), 0, 'SIGUSR1 is no longer pending';
72 local $SIG{USR1} = sub { die "FAIL\n" };
73 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
74 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is blocked';
75 eval { POSIX::sigsuspend(POSIX::SigSet->new) };
76 is $@, "FAIL\n", 'Exception is thrown, so received fourth signal';
77 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $old);
80 local $::TODO = "Needs investigation" if $^O eq 'VMS';
81 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 is still blocked';
85 POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new);
87 is $gotit, 1, 'Haven\'t received fifth signal yet';
88 POSIX::sigprocmask(&POSIX::SIG_UNBLOCK, $new, $old);
89 ok $old->ismember(&POSIX::SIGUSR1), 'SIGUSR1 was still blocked';
90 is $gotit, 2, 'Received fifth signal';
92 # test unsafe signal handlers in combination with exceptions
95 # #89718: on old linux kernels, this test hangs. No-ones thought
96 # of a reliable way to probe for this, so for now, just skip the
97 # tests on production releases
98 skip("some OSes hang here", 3) if (int($]*1000) & 1) == 0;
100 my $action = POSIX::SigAction->new(sub { $gotit--, die }, POSIX::SigSet->new, 0);
101 POSIX::sigaction(&POSIX::SIGALRM, $action);
104 my $set = POSIX::SigSet->new;
105 POSIX::sigprocmask(&POSIX::SIG_BLOCK, undef, $set);
106 is $set->ismember(&POSIX::SIGALRM), 0, "SIGALRM is not blocked on attempt $_";
107 POSIX::sigsuspend($set);
109 is $gotit, 0, 'Received both signals';
114 skip("alarm cannot interrupt blocking system calls on $^O", 2)
115 if $^O =~ /MSWin32|cygwin|VMS/;
117 # make sure the signal handler's called in an eval block *before*
120 $SIG{'ALRM'} = sub { die "HANDLER CALLED\n" };
124 select(undef,undef,undef,10);
127 is($@, "HANDLER CALLED\n", 'block eval');
131 select(undef,undef,undef,10);
134 is($@, "HANDLER CALLED\n", 'string eval');
137 eval { $SIG{"__WARN__\0"} = sub { 1 } };
138 like $@, qr/No such hook: __WARN__\\0 at/, q!Fetching %SIG hooks with an extra trailing nul is nul-clean!;
140 eval { $SIG{"__DIE__\0whoops"} = sub { 1 } };
141 like $@, qr/No such hook: __DIE__\\0whoops at/;
146 local $SIG{__WARN__} = sub { $w = shift };
148 $SIG{"KILL\0"} = sub { 1 };
149 like $w, qr/No such signal: SIGKILL\\0 at/, 'Arbitrary signal lookup through %SIG is clean';
155 local $SIG{INT} = sub { $int_called = 1; };
159 # this is needed to ensure signal delivery on MSWin32