xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/getsid/getsid01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *		07/2001 Ported by Wayne Boyer
5  *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Verify that session IDs returned by getsid() (with argument pid=0)
12  * are same in parent and child process.
13  */
14 
15 
16 #include "tst_test.h"
17 
18 static pid_t p_sid;
19 
run(void)20 static void run(void)
21 {
22 	pid_t pid, c_sid;
23 
24 	TEST(getsid(0));
25 	if (TST_RET == -1) {
26 		tst_res(TFAIL | TTERRNO, "getsid(0) failed in parent");
27 		return;
28 	}
29 
30 	p_sid = TST_RET;
31 
32 	pid = SAFE_FORK();
33 
34 	if (pid == 0) {
35 		TEST(getsid(0));
36 		if (TST_RET == -1) {
37 			tst_res(TFAIL | TTERRNO, "getsid(0) failed in child");
38 			return;
39 		}
40 		c_sid = TST_RET;
41 		TST_EXP_EQ_LI(p_sid, c_sid);
42 	} else {
43 		SAFE_WAITPID(pid, NULL, 0);
44 	}
45 }
46 
47 static struct tst_test test = {
48 	.test_all = run,
49 	.forks_child = 1
50 };
51