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