• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
4  */
5 
6 /*
7  * Test ioctl_ns with NS_GET_PARENT request.
8  *
9  * Tries to get namespace parent for UTS namespace, which
10  * should make the call fail with EINVAL, being a nonhierarchical
11  * namespace.
12  *
13  */
14 #define _GNU_SOURCE
15 
16 #include <errno.h>
17 #include "tst_test.h"
18 #include "lapi/ioctl_ns.h"
19 
setup(void)20 static void setup(void)
21 {
22 	int exists = access("/proc/self/ns/uts", F_OK);
23 
24 	if (exists < 0)
25 		tst_res(TCONF, "namespace not available");
26 }
27 
run(void)28 static void run(void)
29 {
30 	int fd, parent_fd;
31 
32 	fd = SAFE_OPEN("/proc/self/ns/uts", O_RDONLY);
33 	parent_fd = ioctl(fd, NS_GET_PARENT);
34 	if (parent_fd == -1) {
35 		if (errno == ENOTTY)
36 			tst_brk(TCONF, "ioctl(NS_GET_PARENT) not implemented");
37 
38 		if (errno == EINVAL)
39 			tst_res(TPASS, "NS_GET_PARENT fails with EINVAL");
40 		else
41 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
42 	} else {
43 		SAFE_CLOSE(fd);
44 		tst_res(TFAIL, "call to ioctl succeded");
45 	}
46 }
47 
48 static struct tst_test test = {
49 	.test_all = run,
50 	.min_kver = "4.9",
51 	.setup = setup
52 };
53