20 int sigmap
[5] = {SIGKILL
, SIGUSR1
, SIGSEGV
};
23 int main(int argc
, char *argv
[]);
25 void parent(int childpid
);
26 void child(int parpid
);
42 volatile int childsigs
, parsigs
, alarms
;
52 for (i
= 0; i
< ITERATIONS
; i
++) {
53 if (m
& 0001) test5a();
54 if (m
& 0002) test5b();
55 if (m
& 0004) test5c();
56 if (m
& 0010) test5d();
57 if (m
& 0020) test5e();
58 if (m
& 0040) test5f();
59 if (m
& 0100) test5g();
60 if (m
& 0200) test5h();
61 if (m
& 0400) test5i();
64 return(-1); /* impossible */
69 int parpid
, childpid
, flag
, *zp
;
73 for (zp
= &zero
[0]; zp
< &zero
[1024]; zp
++)
74 if (*zp
!= 0) flag
= 1;
75 if (flag
) e(0); /* check if bss is cleared to 0 */
76 if (signal(SIGHUP
, func1
) == SIG_ERR
) e(1);
77 if (signal(SIGUSR1
, func10
) == SIG_ERR
) e(2);
79 if ((childpid
= fork()) != 0) {
80 if (childpid
< 0) ex();
85 if (signal(SIGHUP
, SIG_DFL
) == SIG_ERR
) e(4);
86 if (signal(SIGUSR1
, SIG_DFL
) == SIG_ERR
) e(5);
94 for (i
= 0; i
< 3; i
++) {
95 if (kill(childpid
, SIGHUP
) < 0) e(6);
99 if ( (pid
= wait(&i
)) < 0) e(7);
100 if (i
!= 256 * 6) e(8);
109 for (i
= 0; i
< 3; i
++) {
110 while (childsigs
== 0);
112 if (kill(parpid
, SIGUSR1
) < 0) e(9);
118 int s
; /* for ANSI */
120 if (signal(SIGHUP
, func1
) == SIG_ERR
) e(10);
130 int s
; /* for ANSI */
132 if (signal(SIGUSR1
, func10
) == SIG_ERR
) e(11);
137 int s
; /* for ANSI */
147 if ((pid
= fork()) != 0) {
149 if ((pid
= fork()) != 0) {
151 if ((cpid
= fork()) != 0) {
153 if (kill(cpid
, SIGKILL
) < 0) e(12);
154 if (wait(&n
) < 0) e(13);
155 if (wait(&n
) < 0) e(14);
156 if (wait(&n
) < 0) e(15);
173 /* Test exit status codes for processes killed by signals. */
175 for (i
= 0; i
< 2; i
++) {
176 if ((pid
= fork()) != 0) {
178 sleep(2); /* wait for child to pause */
179 if (kill(pid
, sigmap
[i
]) < 0) {
183 if ((wpid
= wait(&n
)) < 0) e(21);
184 if ((n
& 077) != sigmap
[i
]) e(22);
185 if (pid
!= wpid
) e(23);
201 for (i
= 0; i
< 8; i
++) {
202 signal(SIGALRM
, funcalrm
);
205 if (alarms
!= i
+ 1) e(24);
211 /* When a signal knocks a processes out of WAITPID or PAUSE, it is supposed to
212 * get EINTR as error status. Check that.
217 if (signal(SIGFPE
, func8
) == SIG_ERR
) e(25);
218 if ((n
= fork()) != 0) {
219 /* Parent must delay to give child a chance to pause. */
222 if (kill(n
, SIGFPE
) < 0) e(26);
223 if (wait(&n
) < 0) e(27);
224 if (signal(SIGFPE
, SIG_DFL
) == SIG_ERR
) e(28);
227 if (errno
!= EINTR
&& -errno
!= EINTR
) e(29);
237 if (getuid() != 0) return;
243 if (i
!= (n
& 0377)) e(30);
247 k
= (i
+ j
+ 7) & 0377;
248 if (setgid(k
) < 0) e(31);
249 if (getgid() != k
) e(32);
250 if (getegid() != k
) e(33);
253 k
= (i
+ j
+ 1) & 0377;
254 if (setuid(k
) < 0) e(34);
255 if (getuid() != k
) e(35);
256 if (geteuid() != k
) e(36);
258 if (wait(&j
) != -1) e(37);
268 signal(SIGSEGV
, func11
);
269 signal(SIGSEGV
, SIG_IGN
);
271 if (kill(n
, SIGSEGV
) != 0) e(1);
272 signal(SIGSEGV
, SIG_DFL
);
276 int s
; /* for ANSI */
283 /* When a signal knocks a processes out of PIPE, it is supposed to
284 * get EINTR as error status. Check that.
290 if (signal(SIGFPE
, func8
) == SIG_ERR
) e(1);
292 if ((n
= fork()) != 0) {
293 /* Parent must delay to give child a chance to pause. */
295 while (access("XXX.test5", 0) != 0) /* just wait */ ;
298 if (kill(n
, SIGFPE
) < 0) e(2);
299 if (wait(&n
) < 0) e(3);
300 if (signal(SIGFPE
, SIG_DFL
) == SIG_ERR
) e(4);
301 if (close(fd
[0]) != 0) e(5);
302 if (close(fd
[1]) != 0) e(6);
304 if (creat("XXX.test5", 0777) < 0) e(7);
305 (void) read(fd
[0], (char *) &n
, 1);
306 if (errno
!= EINTR
) e(8);
313 int fd
[2], pid
, buf
[10], n
;
319 if ((pid
= fork()) != 0) {
321 /* Wait until child has started and has created the XXXxxxXXX file. */
322 while (access("XXXxxxXXX", 0) != 0) /* loop */ ;
324 if (kill(pid
, SIGKILL
) != 0) e(1);
325 if (wait(&n
) < 0) e(2);
326 if (close(fd
[0]) != 0) e(3);
327 if (close(fd
[1]) != 0) e(4);
329 if (creat("XXXxxxXXX", 0777) < 0) e(5);
330 read(fd
[0], (char *) buf
, 1);
331 e(5); /* should be killed by signal and not get here */
339 printf("Fork failed: %s (%d)\n", strerror(e
), e
);