• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Ulrich Drepper <drepper@redhat.com>
4  * Copyright (c) International Business Machines Corp., 2009
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Verify that epoll_create1 sets the close-on-exec flag for the returned
11  * file descriptor with EPOLL_CLOEXEC.
12  */
13 
14 #include <sys/epoll.h>
15 
16 #include "tst_test.h"
17 #include "lapi/epoll.h"
18 #include "lapi/syscalls.h"
19 
20 static struct test_case_t {
21 	int flags;
22 	int exp_flag;
23 	const char *desc;
24 } tc[] = {
25 	{0, 0, "without EPOLL_CLOEXEC"},
26 	{EPOLL_CLOEXEC, 1, "with EPOLL_CLOEXEC"}
27 };
28 
run(unsigned int n)29 static void run(unsigned int n)
30 {
31 	int fd, coe;
32 
33 	fd = tst_syscall(__NR_epoll_create1, tc[n].flags);
34 	if (fd == -1)
35 		tst_brk(TFAIL | TERRNO, "epoll_create1(...) failed");
36 
37 	coe = SAFE_FCNTL(fd, F_GETFD);
38 	if ((coe & FD_CLOEXEC) != tc[n].exp_flag)
39 		tst_res(TFAIL, "epoll_create1(...) %s", tc[n].desc);
40 	else
41 		tst_res(TPASS, "epoll_create1(...) %s", tc[n].desc);
42 
43 	SAFE_CLOSE(fd);
44 }
45 
46 static struct tst_test test = {
47 	.min_kver = "2.6.27",
48 	.tcnt = ARRAY_SIZE(tc),
49 	.test = run,
50 };
51