Sun Jul 30 18:31:14 2023 UTC ()
Add EPOLL_CLOEXEC (Theodore Preduta)


(christos)
diff -r1.260 -r1.261 src/sys/compat/linux/common/linux_misc.c
diff -r1.3 -r1.4 src/sys/kern/sys_epoll.c
diff -r1.1 -r1.2 src/sys/sys/epoll.h
diff -r1.1 -r1.2 src/tests/kernel/t_epoll.c

cvs diff -r1.260 -r1.261 src/sys/compat/linux/common/linux_misc.c (expand / switch to unified diff)

--- src/sys/compat/linux/common/linux_misc.c 2023/07/29 15:04:29 1.260
+++ src/sys/compat/linux/common/linux_misc.c 2023/07/30 18:31:13 1.261
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux_misc.c,v 1.260 2023/07/29 15:04:29 christos Exp $ */ 1/* $NetBSD: linux_misc.c,v 1.261 2023/07/30 18:31:13 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe 8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center. 9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -47,27 +47,27 @@ @@ -47,27 +47,27 @@
47 * linux_sys_readdir : linux_misc_notalpha.c 47 * linux_sys_readdir : linux_misc_notalpha.c
48 * linux_sys_setresgid : linux_misc_notalpha.c 48 * linux_sys_setresgid : linux_misc_notalpha.c
49 * linux_sys_time : linux_misc_notalpha.c 49 * linux_sys_time : linux_misc_notalpha.c
50 * linux_sys_utime : linux_misc_notalpha.c 50 * linux_sys_utime : linux_misc_notalpha.c
51 * linux_sys_waitpid : linux_misc_notalpha.c 51 * linux_sys_waitpid : linux_misc_notalpha.c
52 * linux_sys_old_mmap : linux_oldmmap.c 52 * linux_sys_old_mmap : linux_oldmmap.c
53 * linux_sys_oldolduname : linux_oldolduname.c 53 * linux_sys_oldolduname : linux_oldolduname.c
54 * linux_sys_oldselect : linux_oldselect.c 54 * linux_sys_oldselect : linux_oldselect.c
55 * linux_sys_olduname : linux_olduname.c 55 * linux_sys_olduname : linux_olduname.c
56 * linux_sys_pipe : linux_pipe.c 56 * linux_sys_pipe : linux_pipe.c
57 */ 57 */
58 58
59#include <sys/cdefs.h> 59#include <sys/cdefs.h>
60__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.260 2023/07/29 15:04:29 christos Exp $"); 60__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.261 2023/07/30 18:31:13 christos Exp $");
61 61
62#include <sys/param.h> 62#include <sys/param.h>
63#include <sys/systm.h> 63#include <sys/systm.h>
64#include <sys/namei.h> 64#include <sys/namei.h>
65#include <sys/proc.h> 65#include <sys/proc.h>
66#include <sys/dirent.h> 66#include <sys/dirent.h>
67#include <sys/epoll.h> 67#include <sys/epoll.h>
68#include <sys/eventfd.h> 68#include <sys/eventfd.h>
69#include <sys/file.h> 69#include <sys/file.h>
70#include <sys/stat.h> 70#include <sys/stat.h>
71#include <sys/filedesc.h> 71#include <sys/filedesc.h>
72#include <sys/ioctl.h> 72#include <sys/ioctl.h>
73#include <sys/kernel.h> 73#include <sys/kernel.h>
@@ -1715,27 +1715,27 @@ int @@ -1715,27 +1715,27 @@ int
1715linux_sys_epoll_create1(struct lwp *l, 1715linux_sys_epoll_create1(struct lwp *l,
1716 const struct linux_sys_epoll_create1_args *uap, register_t *retval) 1716 const struct linux_sys_epoll_create1_args *uap, register_t *retval)
1717{ 1717{
1718 /* { 1718 /* {
1719 syscallarg(int) flags; 1719 syscallarg(int) flags;
1720 } */ 1720 } */
1721 struct sys_epoll_create1_args ca; 1721 struct sys_epoll_create1_args ca;
1722 1722
1723 if ((SCARG(uap, flags) & ~(LINUX_O_CLOEXEC)) != 0) 1723 if ((SCARG(uap, flags) & ~(LINUX_O_CLOEXEC)) != 0)
1724 return EINVAL; 1724 return EINVAL;
1725 1725
1726 SCARG(&ca, flags) = 0; 1726 SCARG(&ca, flags) = 0;
1727 if ((SCARG(uap, flags) & LINUX_O_CLOEXEC) != 0) 1727 if ((SCARG(uap, flags) & LINUX_O_CLOEXEC) != 0)
1728 SCARG(&ca, flags) |= O_CLOEXEC; 1728 SCARG(&ca, flags) |= EPOLL_CLOEXEC;
1729 1729
1730 return sys_epoll_create1(l, &ca, retval); 1730 return sys_epoll_create1(l, &ca, retval);
1731} 1731}
1732 1732
1733/* 1733/*
1734 * epoll_ctl(2). Copyin event and translate it if necessary and then 1734 * epoll_ctl(2). Copyin event and translate it if necessary and then
1735 * call epoll_ctl_common(). 1735 * call epoll_ctl_common().
1736 */ 1736 */
1737int 1737int
1738linux_sys_epoll_ctl(struct lwp *l, const struct linux_sys_epoll_ctl_args *uap, 1738linux_sys_epoll_ctl(struct lwp *l, const struct linux_sys_epoll_ctl_args *uap,
1739 register_t *retval) 1739 register_t *retval)
1740{ 1740{
1741 /* { 1741 /* {

cvs diff -r1.3 -r1.4 src/sys/kern/sys_epoll.c (expand / switch to unified diff)

--- src/sys/kern/sys_epoll.c 2023/07/30 04:39:00 1.3
+++ src/sys/kern/sys_epoll.c 2023/07/30 18:31:13 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sys_epoll.c,v 1.3 2023/07/30 04:39:00 rin Exp $ */ 1/* $NetBSD: sys_epoll.c,v 1.4 2023/07/30 18:31:13 christos Exp $ */
2 2
3/*- 3/*-
4 * SPDX-License-Identifier: BSD-2-Clause 4 * SPDX-License-Identifier: BSD-2-Clause
5 * 5 *
6 * Copyright (c) 2007 Roman Divacky 6 * Copyright (c) 2007 Roman Divacky
7 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org> 7 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: sys_epoll.c,v 1.3 2023/07/30 04:39:00 rin Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: sys_epoll.c,v 1.4 2023/07/30 18:31:13 christos Exp $");
32 32
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/bitops.h> 36#include <sys/bitops.h>
37#include <sys/epoll.h> 37#include <sys/epoll.h>
38#include <sys/event.h> 38#include <sys/event.h>
39#include <sys/eventvar.h> 39#include <sys/eventvar.h>
40#include <sys/errno.h> 40#include <sys/errno.h>
41#include <sys/file.h> 41#include <sys/file.h>
42#include <sys/filedesc.h> 42#include <sys/filedesc.h>
43#include <sys/fcntl.h> 43#include <sys/fcntl.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
@@ -90,30 +90,32 @@ static int epoll_check_loop_and_depth(st @@ -90,30 +90,32 @@ static int epoll_check_loop_and_depth(st
90 90
91/* 91/*
92 * epoll_create1(2). Parse the flags and then create a kqueue instance. 92 * epoll_create1(2). Parse the flags and then create a kqueue instance.
93 */ 93 */
94int 94int
95sys_epoll_create1(struct lwp *l, const struct sys_epoll_create1_args *uap, 95sys_epoll_create1(struct lwp *l, const struct sys_epoll_create1_args *uap,
96 register_t *retval) 96 register_t *retval)
97{ 97{
98 /* { 98 /* {
99 syscallarg(int) flags; 99 syscallarg(int) flags;
100 } */ 100 } */
101 struct sys_kqueue1_args kqa; 101 struct sys_kqueue1_args kqa;
102 102
103 if ((SCARG(uap, flags) & ~(O_CLOEXEC)) != 0) 103 if ((SCARG(uap, flags) & ~(EPOLL_CLOEXEC)) != 0)
104 return EINVAL; 104 return EINVAL;
105 105
106 SCARG(&kqa, flags) = SCARG(uap, flags); 106 SCARG(&kqa, flags) = 0;
 107 if (SCARG(uap, flags) & EPOLL_CLOEXEC)
 108 SCARG(&kqa, flags) |= O_CLOEXEC;
107 109
108 return sys_kqueue1(l, &kqa, retval); 110 return sys_kqueue1(l, &kqa, retval);
109} 111}
110 112
111/* 113/*
112 * Structure converting function from epoll to kevent. 114 * Structure converting function from epoll to kevent.
113 */ 115 */
114static int 116static int
115epoll_to_kevent(int epfd, int fd, struct epoll_event *l_event, 117epoll_to_kevent(int epfd, int fd, struct epoll_event *l_event,
116 struct kevent *kevent, int *nkevents) 118 struct kevent *kevent, int *nkevents)
117{ 119{
118 uint32_t levents = l_event->events; 120 uint32_t levents = l_event->events;
119 uint32_t kev_flags = EV_ADD | EV_ENABLE; 121 uint32_t kev_flags = EV_ADD | EV_ENABLE;

cvs diff -r1.1 -r1.2 src/sys/sys/epoll.h (expand / switch to unified diff)

--- src/sys/sys/epoll.h 2023/07/28 18:19:01 1.1
+++ src/sys/sys/epoll.h 2023/07/30 18:31:14 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: epoll.h,v 1.1 2023/07/28 18:19:01 christos Exp $ */ 1/* $NetBSD: epoll.h,v 1.2 2023/07/30 18:31:14 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 Roman Divacky 4 * Copyright (c) 2007 Roman Divacky
5 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org> 5 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,30 +21,33 @@ @@ -21,30 +21,33 @@
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 * 27 *
28 * $FreeBSD$ 28 * $FreeBSD$
29 */ 29 */
30 30
31#ifndef _SYS_EPOLL_H_ 31#ifndef _SYS_EPOLL_H_
32#define _SYS_EPOLL_H_ 32#define _SYS_EPOLL_H_
33 33
 34#include <sys/fcntl.h> /* for O_CLOEXEC */
34#include <sys/types.h> /* for uint32_t, uint64_t */ 35#include <sys/types.h> /* for uint32_t, uint64_t */
35#include <sys/sigtypes.h> /* for sigset_t */ 36#include <sys/sigtypes.h> /* for sigset_t */
36struct timespec; 37struct timespec;
37 38
 39#define EPOLL_CLOEXEC O_CLOEXEC
 40
38#define EPOLLIN 0x00000001 41#define EPOLLIN 0x00000001
39#define EPOLLPRI 0x00000002 42#define EPOLLPRI 0x00000002
40#define EPOLLOUT 0x00000004 43#define EPOLLOUT 0x00000004
41#define EPOLLERR 0x00000008 44#define EPOLLERR 0x00000008
42#define EPOLLHUP 0x00000010 45#define EPOLLHUP 0x00000010
43#define EPOLLRDNORM 0x00000040 46#define EPOLLRDNORM 0x00000040
44#define EPOLLRDBAND 0x00000080 47#define EPOLLRDBAND 0x00000080
45#define EPOLLWRNORM 0x00000100 48#define EPOLLWRNORM 0x00000100
46#define EPOLLWRBAND 0x00000200 49#define EPOLLWRBAND 0x00000200
47#define EPOLLMSG 0x00000400 50#define EPOLLMSG 0x00000400
48#define EPOLLRDHUP 0x00002000 51#define EPOLLRDHUP 0x00002000
49#define EPOLLWAKEUP 0x20000000 52#define EPOLLWAKEUP 0x20000000
50#define EPOLLONESHOT 0x40000000 53#define EPOLLONESHOT 0x40000000

cvs diff -r1.1 -r1.2 src/tests/kernel/t_epoll.c (expand / switch to unified diff)

--- src/tests/kernel/t_epoll.c 2023/07/28 18:19:01 1.1
+++ src/tests/kernel/t_epoll.c 2023/07/30 18:31:14 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_epoll.c,v 1.1 2023/07/28 18:19:01 christos Exp $ */ 1/* $NetBSD: t_epoll.c,v 1.2 2023/07/30 18:31:14 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2023 The NetBSD Foundation, Inc. 4 * Copyright (c) 2023 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Theodore Preduta. 8 * by Theodore Preduta.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -19,57 +19,78 @@ @@ -19,57 +19,78 @@
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__RCSID("$NetBSD: t_epoll.c,v 1.1 2023/07/28 18:19:01 christos Exp $"); 32__RCSID("$NetBSD: t_epoll.c,v 1.2 2023/07/30 18:31:14 christos Exp $");
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/epoll.h> 36#include <sys/epoll.h>
 37#include <sys/fcntl.h>
37#include <errno.h> 38#include <errno.h>
38 39
39#include <atf-c.h> 40#include <atf-c.h>
40 41
41#include "h_macros.h" 42#include "h_macros.h"
42 43
43ATF_TC(create_size); 44ATF_TC(create_size);
44ATF_TC_HEAD(create_size, tc) 45ATF_TC_HEAD(create_size, tc)
45{ 46{
46 47
47 atf_tc_set_md_var(tc, "descr", 48 atf_tc_set_md_var(tc, "descr",
48 "Checks that epoll_create requires a non-positive size"); 49 "Checks that epoll_create requires a non-positive size");
49} 50}
50ATF_TC_BODY(create_size, tc) 51ATF_TC_BODY(create_size, tc)
51{ 52{
52 ATF_REQUIRE_EQ_MSG(epoll_create(-1), -1, 53 ATF_REQUIRE_EQ_MSG(epoll_create(-1), -1,
53 "epoll_create succeeded unexpectedly"); 54 "epoll_create succeeded unexpectedly");
54 ATF_REQUIRE_ERRNO(EINVAL, true); 55 ATF_REQUIRE_ERRNO(EINVAL, true);
55 56
56 ATF_REQUIRE_EQ_MSG(epoll_create(0), -1, 57 ATF_REQUIRE_EQ_MSG(epoll_create(0), -1,
57 "epoll_create succeeded unexpectedly"); 58 "epoll_create succeeded unexpectedly");
58 ATF_REQUIRE_ERRNO(EINVAL, true); 59 ATF_REQUIRE_ERRNO(EINVAL, true);
59 60
60 RL(epoll_create(1)); 61 RL(epoll_create(1));
61} 62}
62 63
 64ATF_TC(create_cloexec);
 65ATF_TC_HEAD(create_cloexec, tc)
 66{
 67
 68 atf_tc_set_md_var(tc, "descr",
 69 "Checks that epoll_create1 sets close on exec when desired");
 70}
 71ATF_TC_BODY(create_cloexec, tc)
 72{
 73 int fd;
 74
 75 RL(fd = epoll_create1(0));
 76 ATF_REQUIRE_MSG((fcntl(fd, F_GETFD) & FD_CLOEXEC) == 0,
 77 "Close on exec set unexpectedly.");
 78
 79 RL(fd = epoll_create1(EPOLL_CLOEXEC));
 80 ATF_REQUIRE_MSG((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0,
 81 "Close on exec was not set.");
 82}
 83
63ATF_TC(bad_epfd); 84ATF_TC(bad_epfd);
64ATF_TC_HEAD(bad_epfd, tc) 85ATF_TC_HEAD(bad_epfd, tc)
65{ 86{
66 87
67 atf_tc_set_md_var(tc, "descr", 88 atf_tc_set_md_var(tc, "descr",
68 "Checks that epoll_ctl detects an invalid epfd"); 89 "Checks that epoll_ctl detects an invalid epfd");
69} 90}
70ATF_TC_BODY(bad_epfd, tc) 91ATF_TC_BODY(bad_epfd, tc)
71{ 92{
72 int fd; 93 int fd;
73 struct epoll_event event; 94 struct epoll_event event;
74 95
75 RL(fd = epoll_create1(0)); 96 RL(fd = epoll_create1(0));
@@ -204,22 +225,23 @@ ATF_TC_BODY(watch_depth, tc) @@ -204,22 +225,23 @@ ATF_TC_BODY(watch_depth, tc)
204 RL(tmp = epoll_create1(0)); 225 RL(tmp = epoll_create1(0));
205 RL(epoll_ctl(tmp, EPOLL_CTL_ADD, epfd, &event)); 226 RL(epoll_ctl(tmp, EPOLL_CTL_ADD, epfd, &event));
206 epfd = tmp; 227 epfd = tmp;
207 } 228 }
208 RL(tmp = epoll_create1(0)); 229 RL(tmp = epoll_create1(0));
209 ATF_REQUIRE_EQ_MSG(epoll_ctl(tmp, EPOLL_CTL_ADD, epfd, &event), -1, 230 ATF_REQUIRE_EQ_MSG(epoll_ctl(tmp, EPOLL_CTL_ADD, epfd, &event), -1,
210 "epoll_ctl succeeded unexpectedly"); 231 "epoll_ctl succeeded unexpectedly");
211 ATF_REQUIRE_ERRNO(EINVAL, true); 232 ATF_REQUIRE_ERRNO(EINVAL, true);
212} 233}
213 234
214ATF_TP_ADD_TCS(tp) 235ATF_TP_ADD_TCS(tp)
215{ 236{
216 ATF_TP_ADD_TC(tp, create_size); 237 ATF_TP_ADD_TC(tp, create_size);
 238 ATF_TP_ADD_TC(tp, create_cloexec);
217 ATF_TP_ADD_TC(tp, bad_epfd); 239 ATF_TP_ADD_TC(tp, bad_epfd);
218 ATF_TP_ADD_TC(tp, bad_fd); 240 ATF_TP_ADD_TC(tp, bad_fd);
219 ATF_TP_ADD_TC(tp, not_added); 241 ATF_TP_ADD_TC(tp, not_added);
220 ATF_TP_ADD_TC(tp, watching_self); 242 ATF_TP_ADD_TC(tp, watching_self);
221 ATF_TP_ADD_TC(tp, watch_loops); 243 ATF_TP_ADD_TC(tp, watch_loops);
222 ATF_TP_ADD_TC(tp, watch_depth); 244 ATF_TP_ADD_TC(tp, watch_depth);
223 245
224 return atf_no_error(); 246 return atf_no_error();
225} 247}