• 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_* request for file descriptors
8  * that aren't namespaces.
9  *
10  * Calling ioctl with test directory's file descriptor
11  * should make the call fail with ENOTTY.
12  *
13  */
14 
15 #define _GNU_SOURCE
16 
17 #include <errno.h>
18 #include "tst_test.h"
19 #include "lapi/ioctl_ns.h"
20 
21 static int requests[] = {NS_GET_PARENT, NS_GET_USERNS,
22 	NS_GET_OWNER_UID, NS_GET_NSTYPE};
23 
test_request(unsigned int n)24 static void test_request(unsigned int n)
25 {
26 	int request = requests[n];
27 	int fd, ns_fd;
28 
29 	fd = SAFE_OPEN(".", O_RDONLY);
30 	ns_fd = ioctl(fd, request);
31 	if (ns_fd == -1) {
32 		if (errno == ENOTTY)
33 			tst_res(TPASS, "request failed with ENOTTY");
34 		else
35 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
36 	} else {
37 		tst_res(TFAIL, "request success for invalid fd");
38 		SAFE_CLOSE(ns_fd);
39 	}
40 	SAFE_CLOSE(fd);
41 }
42 
43 static struct tst_test test = {
44 	.tcnt = ARRAY_SIZE(requests),
45 	.test = test_request,
46 	.needs_tmpdir = 1,
47 	.min_kver = "4.11"
48 };
49