Perhaps other OLD_POSIX_API systems might be happy and not only HP-UX 10.20
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / sigaction.t
CommitLineData
1dfe7606 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 unshift @INC, '../lib';
6}
7
8BEGIN{
9 # Don't do anything if POSIX is missing, or sigaction missing.
10 eval { use POSIX; };
2986a63f 11 if($@ || $^O eq 'MSWin32' || $^O eq 'NetWare') {
1dfe7606 12 print "1..0\n";
13 exit 0;
14 }
15}
16
17use strict;
18use vars qw/$bad7 $ok10 $bad18 $ok/;
19
20$^W=1;
21
22print "1..18\n";
23
24sub IGNORE {
25 $bad7=1;
26}
27
28sub DEFAULT {
29 $bad18=1;
30}
31
32sub foo {
33 $ok=1;
34}
35
36my $newaction=POSIX::SigAction->new('::foo', new POSIX::SigSet(SIGUSR1), 0);
37my $oldaction=POSIX::SigAction->new('::bar', new POSIX::SigSet(), 0);
38
39{
40 my $bad;
41 local($SIG{__WARN__})=sub { $bad=1; };
42 sigaction(SIGHUP, $newaction, $oldaction);
43 if($bad) { print "not ok 1\n" } else { print "ok 1\n"}
44}
45
63478870 46if($oldaction->{HANDLER} eq 'DEFAULT' ||
3253b43b 47 $oldaction->{HANDLER} eq 'IGNORE')
63478870 48 { print "ok 2\n" } else { print "not ok 2 # ", $oldaction->{HANDLER}, "\n"}
1dfe7606 49print $SIG{HUP} eq '::foo' ? "ok 3\n" : "not ok 3\n";
50
51sigaction(SIGHUP, $newaction, $oldaction);
52if($oldaction->{HANDLER} eq '::foo')
53 { print "ok 4\n" } else { print "not ok 4\n"}
54if($oldaction->{MASK}->ismember(SIGUSR1))
55 { print "ok 5\n" } else { print "not ok 5\n"}
56if($oldaction->{FLAGS}) {
b13b12d1 57 if ($^O eq 'linux' || $^O eq 'unicos') {
58 print "ok 6 # Skip: sigaction() thinks different in $^O\n";
1dfe7606 59 } else {
60 print "not ok 6\n";
61 }
62} else {
63 print "ok 6\n";
64}
65
66$newaction=POSIX::SigAction->new('IGNORE');
67sigaction(SIGHUP, $newaction);
68kill 'HUP', $$;
69print $bad7 ? "not ok 7\n" : "ok 7\n";
70
71print $SIG{HUP} eq 'IGNORE' ? "ok 8\n" : "not ok 8\n";
72sigaction(SIGHUP, POSIX::SigAction->new('DEFAULT'));
73print $SIG{HUP} eq 'DEFAULT' ? "ok 9\n" : "not ok 9\n";
74
75$newaction=POSIX::SigAction->new(sub { $ok10=1; });
76sigaction(SIGHUP, $newaction);
77{
78 local($^W)=0;
79 kill 'HUP', $$;
80}
81print $ok10 ? "ok 10\n" : "not ok 10\n";
82
83print ref($SIG{HUP}) eq 'CODE' ? "ok 11\n" : "not ok 11\n";
84
85sigaction(SIGHUP, POSIX::SigAction->new('::foo'));
86# Make sure the signal mask gets restored after sigaction croak()s.
87eval {
88 my $act=POSIX::SigAction->new('::foo');
89 delete $act->{HANDLER};
90 sigaction(SIGINT, $act);
91};
92kill 'HUP', $$;
93print $ok ? "ok 12\n" : "not ok 12\n";
94
95undef $ok;
96# Make sure the signal mask gets restored after sigaction returns early.
97my $x=defined sigaction(SIGKILL, $newaction, $oldaction);
98kill 'HUP', $$;
99print !$x && $ok ? "ok 13\n" : "not ok 13\n";
100
101$SIG{HUP}=sub {};
102sigaction(SIGHUP, $newaction, $oldaction);
103print ref($oldaction->{HANDLER}) eq 'CODE' ? "ok 14\n" : "not ok 14\n";
104
105eval {
106 sigaction(SIGHUP, undef, $oldaction);
107};
108print $@ ? "not ok 15\n" : "ok 15\n";
109
110eval {
111 sigaction(SIGHUP, 0, $oldaction);
112};
113print $@ ? "not ok 16\n" : "ok 16\n";
114
115eval {
116 sigaction(SIGHUP, bless({},'Class'), $oldaction);
117};
118print $@ ? "ok 17\n" : "not ok 17\n";
119
cd0683b0 120if ($^O eq 'VMS') {
f6a06849 121 print "ok 18 # Skip: SIGCONT not trappable in $^O\n";
122} else {
123 $newaction=POSIX::SigAction->new(sub { $ok10=1; });
124 if (eval { SIGCONT; 1 }) {
125 sigaction(SIGCONT, POSIX::SigAction->new('DEFAULT'));
126 {
127 local($^W)=0;
128 kill 'CONT', $$;
129 }
4f0c37ba 130 }
f6a06849 131 print $bad18 ? "not ok 18\n" : "ok 18\n";
1dfe7606 132}
1dfe7606 133