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) Crackerjack Project., 2007
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This test is checking if waitid() syscall recognizes a process that has been
11*49cdfc7eSAndroid Build Coastguard Worker * killed with SIGKILL.
12*49cdfc7eSAndroid Build Coastguard Worker */
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker static siginfo_t *infop;
20*49cdfc7eSAndroid Build Coastguard Worker
run(void)21*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
22*49cdfc7eSAndroid Build Coastguard Worker {
23*49cdfc7eSAndroid Build Coastguard Worker pid_t pidchild;
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker pidchild = SAFE_FORK();
26*49cdfc7eSAndroid Build Coastguard Worker if (!pidchild) {
27*49cdfc7eSAndroid Build Coastguard Worker pause();
28*49cdfc7eSAndroid Build Coastguard Worker return;
29*49cdfc7eSAndroid Build Coastguard Worker }
30*49cdfc7eSAndroid Build Coastguard Worker
31*49cdfc7eSAndroid Build Coastguard Worker SAFE_KILL(pidchild, SIGKILL);
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
34*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LI(infop->si_pid, pidchild);
35*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LI(infop->si_status, SIGKILL);
36*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
37*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
41*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
42*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
43*49cdfc7eSAndroid Build Coastguard Worker .bufs = (struct tst_buffers[]) {
44*49cdfc7eSAndroid Build Coastguard Worker {&infop, .size = sizeof(*infop)},
45*49cdfc7eSAndroid Build Coastguard Worker {},
46*49cdfc7eSAndroid Build Coastguard Worker },
47*49cdfc7eSAndroid Build Coastguard Worker };
48