20 int sigmap
[5] = {9, 10, 11};
22 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
23 _PROTOTYPE(void test5a
, (void));
24 _PROTOTYPE(void parent
, (int childpid
));
25 _PROTOTYPE(void child
, (int parpid
));
26 _PROTOTYPE(void func1
, (int s
));
27 _PROTOTYPE(void func8
, (int s
));
28 _PROTOTYPE(void func10
, (int s
));
29 _PROTOTYPE(void func11
, (int s
));
30 _PROTOTYPE(void test5b
, (void));
31 _PROTOTYPE(void test5c
, (void));
32 _PROTOTYPE(void test5d
, (void));
33 _PROTOTYPE(void test5e
, (void));
34 _PROTOTYPE(void test5f
, (void));
35 _PROTOTYPE(void test5g
, (void));
36 _PROTOTYPE(void funcalrm
, (int s
));
37 _PROTOTYPE(void test5h
, (void));
38 _PROTOTYPE(void test5i
, (void));
39 _PROTOTYPE(void ex
, (void));
40 _PROTOTYPE(void e
, (int n
));
41 _PROTOTYPE(void quit
, (void));
44 void (*Signal(int _sig
, void (*_func
)(int)))(int);
45 #define SIG_ZERO ((void (*)(int))0) /* default signal handling */
47 sighandler_t
Signal();
48 /* void (*Signal()) (); */
49 #define SIG_ZERO ((void (*)())0) /* default signal handling */
52 _VOLATILE
int childsigs
, parsigs
, alarms
;
61 fflush(stdout
); /* have to flush for child's benefit */
63 system("rm -rf DIR_05; mkdir DIR_05");
66 for (i
= 0; i
< ITERATIONS
; i
++) {
67 if (m
& 0001) test5a();
68 if (m
& 0002) test5b();
69 if (m
& 0004) test5c();
70 if (m
& 0010) test5d();
71 if (m
& 0020) test5e();
72 if (m
& 0040) test5f();
73 if (m
& 0100) test5g();
74 if (m
& 0200) test5h();
75 if (m
& 0400) test5i();
78 return(-1); /* impossible */
83 int parpid
, childpid
, flag
, *zp
;
87 for (zp
= &zero
[0]; zp
< &zero
[1024]; zp
++)
88 if (*zp
!= 0) flag
= 1;
89 if (flag
) e(0); /* check if bss is cleared to 0 */
90 if (Signal(1, func1
) == SIG_ERR
) e(1);
91 if (Signal(10, func10
) < SIG_ZERO
) e(2);
93 if (childpid
= fork()) {
94 if (childpid
< 0) ex();
99 if (Signal(1, SIG_DFL
) < SIG_ZERO
) e(4);
100 if (Signal(10, SIG_DFL
) < SIG_ZERO
) e(5);
103 void parent(childpid
)
108 for (i
= 0; i
< 3; i
++) {
109 if (kill(childpid
, 1) < 0) e(6);
110 while (parsigs
== 0);
113 if ( (pid
= wait(&i
)) < 0) e(7);
114 if (i
!= 256 * 6) e(8);
123 for (i
= 0; i
< 3; i
++) {
124 while (childsigs
== 0);
126 if (kill(parpid
, 10) < 0) e(9);
132 int s
; /* for ANSI */
134 if (Signal(1, func1
) < SIG_ZERO
) e(10);
144 int s
; /* for ANSI */
146 if (Signal(10, func10
) < SIG_ZERO
) e(11);
151 int s
; /* for ANSI */
161 if ((pid
= fork())) {
163 if ((pid
= fork())) {
167 if (kill(cpid
, 9) < 0) e(12);
168 if (wait(&n
) < 0) e(13);
169 if (wait(&n
) < 0) e(14);
170 if (wait(&n
) < 0) e(15);
187 /* Test exit status codes for processes killed by signals. */
189 for (i
= 0; i
< 2; i
++) {
192 sleep(2); /* wait for child to pause */
193 if (kill(pid
, sigmap
[i
]) < 0) {
197 if ((wpid
= wait(&n
)) < 0) e(21);
198 if ((n
& 077) != sigmap
[i
]) e(22);
199 if (pid
!= wpid
) e(23);
215 for (i
= 0; i
< 8; i
++) {
216 Signal(SIGALRM
, funcalrm
);
219 if (alarms
!= i
+ 1) e(24);
225 /* When a signal knocks a processes out of WAIT or PAUSE, it is supposed to
226 * get EINTR as error status. Check that.
231 if (Signal(8, func8
) < SIG_ZERO
) e(25);
233 /* Parent must delay to give child a chance to pause. */
236 if (kill(n
, 8) < 0) e(26);
237 if (wait(&n
) < 0) e(27);
238 if (Signal(8, SIG_DFL
) < SIG_ZERO
) e(28);
241 if (errno
!= EINTR
&& -errno
!= EINTR
) e(29);
251 if (getuid() != 0) return;
257 if (i
!= (n
& 0377)) e(30);
261 k
= (i
+ j
+ 7) & 0377;
262 if (setgid(k
) < 0) e(31);
263 if (getgid() != k
) e(32);
264 if (getegid() != k
) e(33);
267 k
= (i
+ j
+ 1) & 0377;
268 if (setuid(k
) < 0) e(34);
269 if (getuid() != k
) e(35);
270 if (geteuid() != k
) e(36);
272 if (wait(&j
) != -1) e(37);
285 if (kill(n
, 11) != 0) e(1);
290 int s
; /* for ANSI */
297 /* When a signal knocks a processes out of PIPE, it is supposed to
298 * get EINTR as error status. Check that.
304 if (Signal(8, func8
) < SIG_ZERO
) e(1);
307 /* Parent must delay to give child a chance to pause. */
309 while (access("XXX.test5", 0) != 0) /* just wait */ ;
312 if (kill(n
, 8) < 0) e(2);
313 if (wait(&n
) < 0) e(3);
314 if (Signal(8, SIG_DFL
) < SIG_ZERO
) e(4);
315 if (close(fd
[0]) != 0) e(5);
316 if (close(fd
[1]) != 0) e(6);
318 if (creat("XXX.test5", 0777) < 0) e(7);
319 j
= read(fd
[0], (char *) &n
, 1);
320 if (errno
!= EINTR
) e(8);
327 int fd
[2], pid
, buf
[10], n
;
333 if ( (pid
= fork())) {
335 /* Wait until child has started and has created the XXXxxxXXX file. */
336 while (access("XXXxxxXXX", 0) != 0) /* loop */ ;
338 if (kill(pid
, SIGKILL
) != 0) e(1);
339 if (wait(&n
) < 0) e(2);
340 if (close(fd
[0]) != 0) e(3);
341 if (close(fd
[1]) != 0) e(4);
343 if (creat("XXXxxxXXX", 0777) < 0) e(5);
344 read(fd
[0], (char *) buf
, 1);
345 e(5); /* should be killed by signal and not get here */
353 printf("Fork failed: %s (%d)\n", strerror(e
), e
);
360 int err_num
= errno
; /* save errno in case printf clobbers it */
362 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
363 errno
= err_num
; /* restore errno, just in case */
365 if (errct
++ > MAX_ERROR
) {
366 printf("Too many errors; test aborted\n");
368 system("rm -rf DIR*");
374 void (*Signal(int a
, void (*b
)(int)))(int)
376 sighandler_t
Signal(a
, b
)
381 if (signal(a
, (void (*) ()) b
) == (void (*)()) -1)
391 system("rm -rf DIR*");
397 printf("%d errors\n", errct
);