• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Ulrich Drepper <drepper@redhat.com>
3  * Copyright (c) International Business Machines  Corp., 2009
4  *
5  * This program is free software;  you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  * the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program;
17  *
18  * Test:        epoll_create1_01.c
19  *
20  * Description: This Program tests the new system call introduced in 2.6.27.
21  *              Ulrich´s comment as in:
22  * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a0998b50c3f0b8fdd265c63e0032f86ebe377dbf
23  *
24  * This patch adds the new epoll_create1 syscall.  It extends the old
25  * epoll_create syscall by one parameter which is meant to hold a flag value.
26  * In this patch the only flag support is EPOLL_CLOEXEC which causes the
27  * close-on-exec flag for the returned file descriptor to be set. A new name
28  * EPOLL_CLOEXEC is introduced which in this implementation must have the same
29  * value as O_CLOEXEC.
30  */
31 #include <errno.h>
32 #include <sys/epoll.h>
33 #include "tst_test.h"
34 #include "lapi/epoll.h"
35 #include "lapi/syscalls.h"
36 
verify_epoll_create1(void)37 static void verify_epoll_create1(void)
38 {
39 	int fd, coe;
40 
41 	fd = tst_syscall(__NR_epoll_create1, 0);
42 	if (fd == -1)
43 		tst_brk(TFAIL | TERRNO, "epoll_create1(0) failed");
44 
45 	coe = SAFE_FCNTL(fd, F_GETFD);
46 	if (coe & FD_CLOEXEC)
47 		tst_brk(TFAIL, "flags=0 set close-on-exec flag");
48 
49 	SAFE_CLOSE(fd);
50 
51 	fd = tst_syscall(__NR_epoll_create1, EPOLL_CLOEXEC);
52 	if (fd == -1)
53 		tst_brk(TFAIL | TERRNO, "epoll_create1(EPOLL_CLOEXEC) failed");
54 
55 	coe = SAFE_FCNTL(fd, F_GETFD);
56 	if ((coe & FD_CLOEXEC) == 0)
57 		tst_brk(TFAIL, "flags=EPOLL_CLOEXEC didn't set close-on-exec");
58 
59 	SAFE_CLOSE(fd);
60 
61 	tst_res(TPASS, "epoll_create1(EPOLL_CLOEXEC) PASSED");
62 }
63 
64 static struct tst_test test = {
65 	.min_kver = "2.6.27",
66 	.test_all = verify_epoll_create1,
67 };
68