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