Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
add definition for epoll
Browse files Browse the repository at this point in the history
  • Loading branch information
6167656e74323431 committed Jul 30, 2023
1 parent f35e93f commit 91c78e0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sys/compat/linux/common/linux_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,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);
}
Expand Down
6 changes: 4 additions & 2 deletions sys/kern/sys_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,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);
}
Expand Down
3 changes: 3 additions & 0 deletions sys/sys/epoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,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
Expand Down
22 changes: 22 additions & 0 deletions tests/kernel/t_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <sys/fcntl.h>
#include <errno.h>

#include <atf-c.h>
Expand All @@ -56,6 +57,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)
{
Expand Down Expand Up @@ -210,6 +231,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);
Expand Down

0 comments on commit 91c78e0

Please sign in to comment.