xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/wait4/wait402.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2001
4  * Copyright (c) 2012 Cyril Hrubis <[email protected]>
5  * Copyright (c) Linux Test Project, 2001-2015
6  * Copyright (c) 2023 Ioannis Bonatakis <[email protected]>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Check for ECHILD errno when call wait4(2) with an invalid pid value.
13  */
14 
15 #include "tst_test.h"
16 #include <sys/wait.h>
17 
18 static pid_t pid_max;
19 
run(void)20 static void run(void)
21 {
22 	int status;
23 	struct rusage rusage;
24 
25 	TST_EXP_FAIL2(wait4(pid_max + 1, &status, 0, &rusage), ECHILD);
26 }
27 
setup(void)28 static void setup(void)
29 {
30 	SAFE_FILE_SCANF("/proc/sys/kernel/pid_max", "%d\n", &pid_max);
31 }
32 
33 static struct tst_test test = {
34 	.test_all = run,
35 	.setup = setup,
36 };
37