1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * Test case to check the basic functionality of kill() when killing an
6*49cdfc7eSAndroid Build Coastguard Worker * entire process group with a negative pid.
7*49cdfc7eSAndroid Build Coastguard Worker *
8*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
9*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
10*49cdfc7eSAndroid Build Coastguard Worker */
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker
verify_kill(void)19*49cdfc7eSAndroid Build Coastguard Worker static void verify_kill(void)
20*49cdfc7eSAndroid Build Coastguard Worker {
21*49cdfc7eSAndroid Build Coastguard Worker int nsig, i, status;
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker if (!SAFE_FORK()) {
24*49cdfc7eSAndroid Build Coastguard Worker setpgrp();
25*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < 5; i++) {
26*49cdfc7eSAndroid Build Coastguard Worker if (!SAFE_FORK())
27*49cdfc7eSAndroid Build Coastguard Worker pause();
28*49cdfc7eSAndroid Build Coastguard Worker }
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker TEST(kill(-getpgrp(), SIGKILL));
31*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET != 0)
32*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "kill failed");
33*49cdfc7eSAndroid Build Coastguard Worker exit(0);
34*49cdfc7eSAndroid Build Coastguard Worker }
35*49cdfc7eSAndroid Build Coastguard Worker
36*49cdfc7eSAndroid Build Coastguard Worker SAFE_WAITPID(-1, &status, 0);
37*49cdfc7eSAndroid Build Coastguard Worker nsig = WTERMSIG(status);
38*49cdfc7eSAndroid Build Coastguard Worker if (nsig != SIGKILL) {
39*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TFAIL, "wait: unexpected signal %d returned, "
40*49cdfc7eSAndroid Build Coastguard Worker "expected SIGKILL(9)", nsig);
41*49cdfc7eSAndroid Build Coastguard Worker }
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "receive expected signal SIGKILL(9)");
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
48*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_kill,
49*49cdfc7eSAndroid Build Coastguard Worker };
50