1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (C) International Business Machines Corp., 2008 4f08c3bdfSopenharmony_ci * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Clone a process with CLONE_NEWPID flag and check that child container does 11f08c3bdfSopenharmony_ci * not get kill itself with SIGKILL. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include <sys/wait.h> 15f08c3bdfSopenharmony_ci#include "tst_test.h" 16f08c3bdfSopenharmony_ci#include "lapi/sched.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic void child_func(void) 19f08c3bdfSopenharmony_ci{ 20f08c3bdfSopenharmony_ci pid_t cpid = tst_getpid(); 21f08c3bdfSopenharmony_ci pid_t ppid = getppid(); 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(cpid, 1); 24f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(ppid, 0); 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci tst_res(TINFO, "Trying to kill container from within container"); 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci SAFE_KILL(1, SIGKILL); 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci tst_res(TINFO, "Container is up and running"); 31f08c3bdfSopenharmony_ci} 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_cistatic void run(void) 34f08c3bdfSopenharmony_ci{ 35f08c3bdfSopenharmony_ci const struct tst_clone_args args = { 36f08c3bdfSopenharmony_ci .flags = CLONE_NEWPID, 37f08c3bdfSopenharmony_ci .exit_signal = SIGCHLD, 38f08c3bdfSopenharmony_ci }; 39f08c3bdfSopenharmony_ci pid_t pid; 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci pid = SAFE_CLONE(&args); 42f08c3bdfSopenharmony_ci if (!pid) { 43f08c3bdfSopenharmony_ci child_func(); 44f08c3bdfSopenharmony_ci return; 45f08c3bdfSopenharmony_ci } 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci tst_reap_children(); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .test_all = run, 52f08c3bdfSopenharmony_ci .needs_root = 1, 53f08c3bdfSopenharmony_ci .forks_child = 1, 54f08c3bdfSopenharmony_ci}; 55