Add EPOLL_CLOEXEC (Theodore Preduta)

This commit is contained in:
christos 2023-07-30 18:31:13 +00:00
parent f381a67eb4
commit 2c545067c7
4 changed files with 37 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_misc.c,v 1.260 2023/07/29 15:04:29 christos Exp $ */
/* $NetBSD: linux_misc.c,v 1.261 2023/07/30 18:31:13 christos Exp $ */
/*-
* Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.260 2023/07/29 15:04:29 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.261 2023/07/30 18:31:13 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1725,7 +1725,7 @@ linux_sys_epoll_create1(struct lwp *l,
SCARG(&ca, flags) = 0;
if ((SCARG(uap, flags) & LINUX_O_CLOEXEC) != 0)
SCARG(&ca, flags) |= O_CLOEXEC;
SCARG(&ca, flags) |= EPOLL_CLOEXEC;
return sys_epoll_create1(l, &ca, retval);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_epoll.c,v 1.3 2023/07/30 04:39:00 rin Exp $ */
/* $NetBSD: sys_epoll.c,v 1.4 2023/07/30 18:31:13 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause
@ -28,7 +28,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_epoll.c,v 1.3 2023/07/30 04:39:00 rin Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_epoll.c,v 1.4 2023/07/30 18:31:13 christos Exp $");
#include <sys/param.h>
@ -100,10 +100,12 @@ sys_epoll_create1(struct lwp *l, const struct sys_epoll_create1_args *uap,
} */
struct sys_kqueue1_args kqa;
if ((SCARG(uap, flags) & ~(O_CLOEXEC)) != 0)
if ((SCARG(uap, flags) & ~(EPOLL_CLOEXEC)) != 0)
return EINVAL;
SCARG(&kqa, flags) = SCARG(uap, flags);
SCARG(&kqa, flags) = 0;
if (SCARG(uap, flags) & EPOLL_CLOEXEC)
SCARG(&kqa, flags) |= O_CLOEXEC;
return sys_kqueue1(l, &kqa, retval);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: epoll.h,v 1.1 2023/07/28 18:19:01 christos Exp $ */
/* $NetBSD: epoll.h,v 1.2 2023/07/30 18:31:14 christos Exp $ */
/*-
* Copyright (c) 2007 Roman Divacky
@ -31,10 +31,13 @@
#ifndef _SYS_EPOLL_H_
#define _SYS_EPOLL_H_
#include <sys/fcntl.h> /* for O_CLOEXEC */
#include <sys/types.h> /* for uint32_t, uint64_t */
#include <sys/sigtypes.h> /* for sigset_t */
struct timespec;
#define EPOLL_CLOEXEC O_CLOEXEC
#define EPOLLIN 0x00000001
#define EPOLLPRI 0x00000002
#define EPOLLOUT 0x00000004

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_epoll.c,v 1.1 2023/07/28 18:19:01 christos Exp $ */
/* $NetBSD: t_epoll.c,v 1.2 2023/07/30 18:31:14 christos Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@ -29,11 +29,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_epoll.c,v 1.1 2023/07/28 18:19:01 christos Exp $");
__RCSID("$NetBSD: t_epoll.c,v 1.2 2023/07/30 18:31:14 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <atf-c.h>
@ -60,6 +61,26 @@ ATF_TC_BODY(create_size, tc)
RL(epoll_create(1));
}
ATF_TC(create_cloexec);
ATF_TC_HEAD(create_cloexec, tc)
{
atf_tc_set_md_var(tc, "descr",
"Checks that epoll_create1 sets close on exec when desired");
}
ATF_TC_BODY(create_cloexec, tc)
{
int fd;
RL(fd = epoll_create1(0));
ATF_REQUIRE_MSG((fcntl(fd, F_GETFD) & FD_CLOEXEC) == 0,
"Close on exec set unexpectedly.");
RL(fd = epoll_create1(EPOLL_CLOEXEC));
ATF_REQUIRE_MSG((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0,
"Close on exec was not set.");
}
ATF_TC(bad_epfd);
ATF_TC_HEAD(bad_epfd, tc)
{
@ -214,6 +235,7 @@ ATF_TC_BODY(watch_depth, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, create_size);
ATF_TP_ADD_TC(tp, create_cloexec);
ATF_TP_ADD_TC(tp, bad_epfd);
ATF_TP_ADD_TC(tp, bad_fd);
ATF_TP_ADD_TC(tp, not_added);