1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) International Business Machines Corp., 2008
4 * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Clone a process with CLONE_NEWPID flag and check that killing subprocesses
11 * from child namespace will raise ESRCH error.
12 */
13
14 #include "tst_test.h"
15 #include "lapi/sched.h"
16
child_func(void)17 static void child_func(void)
18 {
19 pid_t cpid = tst_getpid();
20 pid_t ppid = getppid();
21
22 TST_EXP_EQ_LI(cpid, 1);
23 TST_EXP_EQ_LI(ppid, 0);
24
25 tst_res(TINFO, "Trying to kill all subprocesses from within container");
26
27 TST_EXP_FAIL(kill(-1, SIGKILL), ESRCH);
28 }
29
run(void)30 static void run(void)
31 {
32 const struct tst_clone_args args = {
33 .flags = CLONE_NEWPID,
34 .exit_signal = SIGCHLD,
35 };
36
37 if (!SAFE_CLONE(&args)) {
38 child_func();
39 return;
40 }
41 }
42
43 static struct tst_test test = {
44 .test_all = run,
45 .needs_root = 1,
46 .forks_child = 1,
47 };
48