• 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  * Test system call introduced in 2.6.27.
7  * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a0998b50c3f0b8fdd265c63e0032f86ebe377dbf
8  *
9  * This patch adds the new epoll_create1 syscall.  It extends the old
10  * epoll_create syscall by one parameter which is meant to hold a flag value.
11  * In this patch the only flag support is EPOLL_CLOEXEC which causes the
12  * close-on-exec flag for the returned file descriptor to be set. A new name
13  * EPOLL_CLOEXEC is introduced which in this implementation must have the same
14  * value as O_CLOEXEC.
15  */
16 #include <errno.h>
17 #include <sys/epoll.h>
18 #include "tst_test.h"
19 #include "lapi/epoll.h"
20 #include "lapi/syscalls.h"
21 
verify_epoll_create1(void)22 static void verify_epoll_create1(void)
23 {
24 	int fd, coe;
25 
26 	fd = tst_syscall(__NR_epoll_create1, 0);
27 	if (fd == -1)
28 		tst_brk(TFAIL | TERRNO, "epoll_create1(0) failed");
29 
30 	coe = SAFE_FCNTL(fd, F_GETFD);
31 	if (coe & FD_CLOEXEC)
32 		tst_brk(TFAIL, "flags=0 set close-on-exec flag");
33 
34 	SAFE_CLOSE(fd);
35 
36 	fd = tst_syscall(__NR_epoll_create1, EPOLL_CLOEXEC);
37 	if (fd == -1)
38 		tst_brk(TFAIL | TERRNO, "epoll_create1(EPOLL_CLOEXEC) failed");
39 
40 	coe = SAFE_FCNTL(fd, F_GETFD);
41 	if ((coe & FD_CLOEXEC) == 0)
42 		tst_brk(TFAIL, "flags=EPOLL_CLOEXEC didn't set close-on-exec");
43 
44 	SAFE_CLOSE(fd);
45 
46 	tst_res(TPASS, "epoll_create1(EPOLL_CLOEXEC) PASSED");
47 }
48 
49 static struct tst_test test = {
50 	.min_kver = "2.6.27",
51 	.test_all = verify_epoll_create1,
52 };
53