1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Crackerjack Project., 2007
4 * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
5 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Tests if waitid() filters children correctly by the PID.
12 *
13 * - waitid() with PID + 1 returns ECHILD
14 * - waitid() with PID returns correct data
15 */
16
17 #include <stdlib.h>
18 #include <sys/wait.h>
19 #include "tst_test.h"
20
21 static siginfo_t *infop;
22
run(void)23 static void run(void)
24 {
25 pid_t pid_child;
26
27 pid_child = SAFE_FORK();
28 if (!pid_child)
29 exit(0);
30
31 TST_EXP_FAIL(waitid(P_PID, pid_child+1, infop, WEXITED), ECHILD);
32
33 memset(infop, 0, sizeof(*infop));
34 TST_EXP_PASS(waitid(P_PID, pid_child, infop, WEXITED));
35
36 TST_EXP_EQ_LI(infop->si_pid, pid_child);
37 TST_EXP_EQ_LI(infop->si_status, 0);
38 TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
39 TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
40 }
41
42 static struct tst_test test = {
43 .test_all = run,
44 .forks_child = 1,
45 .bufs = (struct tst_buffers[]) {
46 {&infop, .size = sizeof(*infop)},
47 {}
48 }
49 };
50