1 /* Copyright (c) 2014 Red Hat, Inc.
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of version 2 the GNU General Public License as
5 * published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "libclone.h"
17 #include "test.h"
18 #include "safe_macros.h"
19
20 #define DIRA "A"
21 #define DIRB "B"
22
dummy_child(void * v)23 static int dummy_child(void *v)
24 {
25 (void) v;
26 return 0;
27 }
28
check_newns(void)29 static int check_newns(void)
30 {
31 int pid, status;
32
33 if (tst_kvercmp(2, 4, 19) < 0)
34 tst_brkm(TCONF, NULL, "CLONE_NEWNS not supported");
35
36 pid = do_clone_unshare_test(T_CLONE, CLONE_NEWNS, dummy_child, NULL);
37 if (pid == -1)
38 tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWNS not supported");
39 SAFE_WAIT(NULL, &status);
40
41 return 0;
42 }
43
cleanup(void)44 static void cleanup(void)
45 {
46 umount(DIRA);
47 umount(DIRB);
48 tst_rmdir();
49 }
50
setup(void)51 static void setup(void)
52 {
53 tst_require_root();
54 check_newns();
55 tst_tmpdir();
56 TST_CHECKPOINT_INIT(tst_rmdir);
57 SAFE_MKDIR(cleanup, DIRA, 0777);
58 SAFE_MKDIR(cleanup, DIRB, 0777);
59 SAFE_TOUCH(cleanup, DIRA"/A", 0, NULL);
60 SAFE_TOUCH(cleanup, DIRB"/B", 0, NULL);
61 }
62