• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2007
4  * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Clone a process with CLONE_NEWPID flag and check:
11  *
12  * - child session ID must be 1
13  * - parent process group ID must be 1
14  */
15 
16 #include "tst_test.h"
17 #include "lapi/sched.h"
18 
child_func(void)19 static void child_func(void)
20 {
21 	TST_EXP_EQ_LI(getsid(0), 0);
22 	TST_EXP_EQ_LI(getpgid(0), 0);
23 
24 	tst_res(TINFO, "setsid()");
25 	SAFE_SETSID();
26 
27 	TST_EXP_EQ_LI(getsid(0), 1);
28 	TST_EXP_EQ_LI(getpgid(0), 1);
29 }
30 
run(void)31 static void run(void)
32 {
33 	const struct tst_clone_args args = {
34 		.flags = CLONE_NEWPID,
35 		.exit_signal = SIGCHLD,
36 	};
37 
38 	if (!SAFE_CLONE(&args)) {
39 		child_func();
40 		return;
41 	}
42 }
43 
44 static struct tst_test test = {
45 	.test_all = run,
46 	.needs_root = 1,
47 	.forks_child = 1,
48 	.needs_kconfigs = (const char *[]) {
49 		"CONFIG_PID_NS",
50 		NULL,
51 	},
52 };
53