1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Crackerjack Project., 2007
4 * Copyright (c) Manas Kumar Nayak [email protected]>
5 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Test if waitid() filters children killed with SIGCONT.
12 */
13
14 #include <sys/wait.h>
15 #include "tst_test.h"
16
17 static siginfo_t *infop;
18
run(void)19 static void run(void)
20 {
21 pid_t pid_child;
22
23 pid_child = SAFE_FORK();
24 if (!pid_child) {
25 SAFE_KILL(getpid(), SIGSTOP);
26 TST_CHECKPOINT_WAIT(0);
27 return;
28 }
29
30 tst_res(TINFO, "send SIGCONT to child");
31
32 memset(infop, 0, sizeof(*infop));
33 TST_EXP_PASS(waitid(P_PID, pid_child, infop, WSTOPPED));
34
35 TST_EXP_EQ_LI(infop->si_pid, pid_child);
36 TST_EXP_EQ_LI(infop->si_status, SIGSTOP);
37 TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
38 TST_EXP_EQ_LI(infop->si_code, CLD_STOPPED);
39
40 SAFE_KILL(pid_child, SIGCONT);
41
42 tst_res(TINFO, "filter child by WCONTINUED");
43
44 memset(infop, 0, sizeof(*infop));
45 TST_EXP_PASS(waitid(P_PID, pid_child, infop, WCONTINUED));
46
47 TST_EXP_EQ_LI(infop->si_pid, pid_child);
48 TST_EXP_EQ_LI(infop->si_status, SIGCONT);
49 TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
50 TST_EXP_EQ_LI(infop->si_code, CLD_CONTINUED);
51
52 TST_CHECKPOINT_WAKE(0);
53 }
54
55 static struct tst_test test = {
56 .test_all = run,
57 .forks_child = 1,
58 .needs_checkpoints = 1,
59 .bufs = (struct tst_buffers[]) {
60 {&infop, .size = sizeof(*infop)},
61 {}
62 }
63 };
64