xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/waitid/waitid09.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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) Manas Kumar Nayak [email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Test that waitid() fails with ECHILD with process that is not child of the
12*49cdfc7eSAndroid Build Coastguard Worker  * current process. We fork() one child just to be sure that there are unwaited
13*49cdfc7eSAndroid Build Coastguard Worker  * for children available while the test runs.
14*49cdfc7eSAndroid Build Coastguard Worker  */
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker static siginfo_t *infop;
21*49cdfc7eSAndroid Build Coastguard Worker 
run(void)22*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
23*49cdfc7eSAndroid Build Coastguard Worker {
24*49cdfc7eSAndroid Build Coastguard Worker 	if (!SAFE_FORK())
25*49cdfc7eSAndroid Build Coastguard Worker 		exit(0);
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(waitid(P_PID, 1, infop, WEXITED), ECHILD);
28*49cdfc7eSAndroid Build Coastguard Worker }
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
31*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
32*49cdfc7eSAndroid Build Coastguard Worker 	.forks_child = 1,
33*49cdfc7eSAndroid Build Coastguard Worker 	.bufs = (struct tst_buffers[]) {
34*49cdfc7eSAndroid Build Coastguard Worker 		{&infop, .size = sizeof(*infop)},
35*49cdfc7eSAndroid Build Coastguard Worker 		{}
36*49cdfc7eSAndroid Build Coastguard Worker 	}
37*49cdfc7eSAndroid Build Coastguard Worker };
38