18 int sigmap
[5] = {9, 10, 11};
22 int main(int argc
, char *argv
[]);
24 void parent(int childpid
);
25 void child(int parpid
);
41 volatile int childsigs
, parsigs
, alarms
;
51 for (i
= 0; i
< ITERATIONS
; i
++) {
52 if (m
& 0001) test5a();
53 if (m
& 0002) test5b();
54 if (m
& 0004) test5c();
55 if (m
& 0010) test5d();
56 if (m
& 0020) test5e();
57 if (m
& 0040) test5f();
58 if (m
& 0100) test5g();
59 if (m
& 0200) test5h();
60 if (m
& 0400) test5i();
63 return(-1); /* impossible */
68 int parpid
, childpid
, flag
, *zp
;
72 for (zp
= &zero
[0]; zp
< &zero
[1024]; zp
++)
73 if (*zp
!= 0) flag
= 1;
74 if (flag
) e(0); /* check if bss is cleared to 0 */
75 if (signal(1, func1
) == SIG_ERR
) e(1);
76 if (signal(10, func10
) == SIG_ERR
) e(2);
78 if ((childpid
= fork()) != 0) {
79 if (childpid
< 0) ex();
84 if (signal(1, SIG_DFL
) == SIG_ERR
) e(4);
85 if (signal(10, SIG_DFL
) == SIG_ERR
) e(5);
93 for (i
= 0; i
< 3; i
++) {
94 if (kill(childpid
, 1) < 0) e(6);
98 if ( (pid
= wait(&i
)) < 0) e(7);
99 if (i
!= 256 * 6) e(8);
108 for (i
= 0; i
< 3; i
++) {
109 while (childsigs
== 0);
111 if (kill(parpid
, 10) < 0) e(9);
117 int s
; /* for ANSI */
119 if (signal(1, func1
) == SIG_ERR
) e(10);
129 int s
; /* for ANSI */
131 if (signal(10, func10
) == SIG_ERR
) e(11);
136 int s
; /* for ANSI */
146 if ((pid
= fork()) != 0) {
148 if ((pid
= fork()) != 0) {
150 if ((cpid
= fork()) != 0) {
152 if (kill(cpid
, 9) < 0) e(12);
153 if (wait(&n
) < 0) e(13);
154 if (wait(&n
) < 0) e(14);
155 if (wait(&n
) < 0) e(15);
172 /* Test exit status codes for processes killed by signals. */
174 for (i
= 0; i
< 2; i
++) {
175 if ((pid
= fork()) != 0) {
177 sleep(2); /* wait for child to pause */
178 if (kill(pid
, sigmap
[i
]) < 0) {
182 if ((wpid
= wait(&n
)) < 0) e(21);
183 if ((n
& 077) != sigmap
[i
]) e(22);
184 if (pid
!= wpid
) e(23);
200 for (i
= 0; i
< 8; i
++) {
201 signal(SIGALRM
, funcalrm
);
204 if (alarms
!= i
+ 1) e(24);
210 /* When a signal knocks a processes out of WAIT or PAUSE, it is supposed to
211 * get EINTR as error status. Check that.
216 if (signal(8, func8
) == SIG_ERR
) e(25);
217 if ((n
= fork()) != 0) {
218 /* Parent must delay to give child a chance to pause. */
221 if (kill(n
, 8) < 0) e(26);
222 if (wait(&n
) < 0) e(27);
223 if (signal(8, SIG_DFL
) == SIG_ERR
) e(28);
226 if (errno
!= EINTR
&& -errno
!= EINTR
) e(29);
236 if (getuid() != 0) return;
242 if (i
!= (n
& 0377)) e(30);
246 k
= (i
+ j
+ 7) & 0377;
247 if (setgid(k
) < 0) e(31);
248 if (getgid() != k
) e(32);
249 if (getegid() != k
) e(33);
252 k
= (i
+ j
+ 1) & 0377;
253 if (setuid(k
) < 0) e(34);
254 if (getuid() != k
) e(35);
255 if (geteuid() != k
) e(36);
257 if (wait(&j
) != -1) e(37);
270 if (kill(n
, 11) != 0) e(1);
275 int s
; /* for ANSI */
282 /* When a signal knocks a processes out of PIPE, it is supposed to
283 * get EINTR as error status. Check that.
289 if (signal(8, func8
) == SIG_ERR
) e(1);
291 if ((n
= fork()) != 0) {
292 /* Parent must delay to give child a chance to pause. */
294 while (access("XXX.test5", 0) != 0) /* just wait */ ;
297 if (kill(n
, 8) < 0) e(2);
298 if (wait(&n
) < 0) e(3);
299 if (signal(8, SIG_DFL
) == SIG_ERR
) e(4);
300 if (close(fd
[0]) != 0) e(5);
301 if (close(fd
[1]) != 0) e(6);
303 if (creat("XXX.test5", 0777) < 0) e(7);
304 j
= read(fd
[0], (char *) &n
, 1);
305 if (errno
!= EINTR
) e(8);
312 int fd
[2], pid
, buf
[10], n
;
318 if ((pid
= fork()) != 0) {
320 /* Wait until child has started and has created the XXXxxxXXX file. */
321 while (access("XXXxxxXXX", 0) != 0) /* loop */ ;
323 if (kill(pid
, SIGKILL
) != 0) e(1);
324 if (wait(&n
) < 0) e(2);
325 if (close(fd
[0]) != 0) e(3);
326 if (close(fd
[1]) != 0) e(4);
328 if (creat("XXXxxxXXX", 0777) < 0) e(5);
329 read(fd
[0], (char *) buf
, 1);
330 e(5); /* should be killed by signal and not get here */
338 printf("Fork failed: %s (%d)\n", strerror(e
), e
);