1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Crackerjack Project., 2007 4f08c3bdfSopenharmony_ci * Ported from Crackerjack to LTP by Manas Kumar Nayak maknayak@in.ibm.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Basic tests for the unshare() syscall. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * [Algorithm] 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * Calls unshare() for different CLONE_* flags in a child process and expects 15f08c3bdfSopenharmony_ci * them to succeed. 16f08c3bdfSopenharmony_ci */ 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#define _GNU_SOURCE 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci#include <stdio.h> 21f08c3bdfSopenharmony_ci#include <sys/wait.h> 22f08c3bdfSopenharmony_ci#include <sys/types.h> 23f08c3bdfSopenharmony_ci#include <sys/param.h> 24f08c3bdfSopenharmony_ci#include <sys/syscall.h> 25f08c3bdfSopenharmony_ci#include <sched.h> 26f08c3bdfSopenharmony_ci#include <limits.h> 27f08c3bdfSopenharmony_ci#include <unistd.h> 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci#include "tst_test.h" 30f08c3bdfSopenharmony_ci#include "config.h" 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci#ifdef HAVE_UNSHARE 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_cistatic struct test_case_t { 35f08c3bdfSopenharmony_ci int mode; 36f08c3bdfSopenharmony_ci const char *desc; 37f08c3bdfSopenharmony_ci} tc[] = { 38f08c3bdfSopenharmony_ci {CLONE_FILES, "CLONE_FILES"}, 39f08c3bdfSopenharmony_ci {CLONE_FS, "CLONE_FS"}, 40f08c3bdfSopenharmony_ci {CLONE_NEWNS, "CLONE_NEWNS"}, 41f08c3bdfSopenharmony_ci}; 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic void run(unsigned int i) 44f08c3bdfSopenharmony_ci{ 45f08c3bdfSopenharmony_ci pid_t pid = SAFE_FORK(); 46f08c3bdfSopenharmony_ci if (pid == 0) 47f08c3bdfSopenharmony_ci TST_EXP_PASS(unshare(tc[i].mode), "unshare(%s)", tc[i].desc); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tc), 52f08c3bdfSopenharmony_ci .forks_child = 1, 53f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 54f08c3bdfSopenharmony_ci .needs_root = 1, 55f08c3bdfSopenharmony_ci .test = run, 56f08c3bdfSopenharmony_ci}; 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_ci#else 59f08c3bdfSopenharmony_ciTST_TEST_TCONF("unshare is undefined."); 60f08c3bdfSopenharmony_ci#endif 61