xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/vhangup/vhangup02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  * History
6  *	07/2001 John George
7  *		-Ported
8  */
9 
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <errno.h>
13 #include <pwd.h>
14 #include <sys/wait.h>
15 #include "tst_test.h"
16 #include "lapi/syscalls.h"
17 
run(void)18 static void run(void)
19 {
20 	pid_t pid, pid1;
21 
22 	pid = SAFE_FORK();
23 	if (pid > 0) {
24 		waitpid(pid, NULL, 0);
25 	} else {
26 		pid1 = setsid();
27 		if (pid1 < 0)
28 			tst_brk(TBROK | TTERRNO, "setsid failed");
29 		TEST(tst_syscall(__NR_vhangup));
30 		if (TST_RET == -1)
31 			tst_res(TFAIL | TTERRNO, "vhangup() failed");
32 		else
33 			tst_res(TPASS, "vhangup() succeeded");
34 	}
35 }
36 
37 static struct tst_test test = {
38 	.test_all = run,
39 	.forks_child = 1,
40 	.needs_root = 1,
41 };
42