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