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 * This test if waitid() syscall leaves the si_pid set to 0 with WNOHANG flag
12 * when no child was waited for.
13 */
14
15 #include <sys/wait.h>
16 #include "tst_test.h"
17
18 static siginfo_t *infop;
19
run(void)20 static void run(void)
21 {
22 pid_t pid_child;
23
24 pid_child = SAFE_FORK();
25 if (!pid_child) {
26 TST_CHECKPOINT_WAIT(0);
27 return;
28 }
29
30 memset(infop, 0, sizeof(*infop));
31 TST_EXP_PASS(waitid(P_ALL, pid_child, infop, WNOHANG | WEXITED));
32
33 TST_EXP_EQ_LI(infop->si_pid, 0);
34
35 TST_CHECKPOINT_WAKE(0);
36 }
37
38 static struct tst_test test = {
39 .test_all = run,
40 .forks_child = 1,
41 .needs_checkpoints = 1,
42 .bufs = (struct tst_buffers[]) {
43 {&infop, .size = sizeof(*infop)},
44 {}
45 }
46 };
47