Skip to content

Commit

Permalink
fix issue 49
Browse files Browse the repository at this point in the history
  • Loading branch information
jiixyj committed Jun 8, 2024
1 parent 7144c68 commit 3139d76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/epollfd_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ epollfd_ctx_add_node(EpollFDCtx *epollfd, int kq, int fd2,
* On FreeBSD we need to distinguish between kqueues
* and native eventfds.
*/
if (ioctl(fd2_node->fd, FIONBIO, &tmp) < 0 &&
errno == ENOTTY) {
if (kevent(fd2_node->fd, NULL, 0, NULL, 0,
&(struct timespec) { 0, 0 }) == 0) {
fd2_node->node_type = NODE_TYPE_KQUEUE;
} else {
fd2_node->node_type = NODE_TYPE_OTHER;
Expand Down
26 changes: 26 additions & 0 deletions test/epoll-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,31 @@ ATF_TC_BODY_FD_LEAKCHECK(epoll__fcntl_fl, tcptr)
#endif
}

// Test adapted from <https://github.com/jiixyj/epoll-shim/issues/49>.
ATF_TC_WITHOUT_HEAD(epoll__fcntl_issue49);
ATF_TC_BODY_FD_LEAKCHECK(epoll__fcntl_issue49, tcptr)
{
int fd = eventfd(0, EFD_NONBLOCK);
ATF_REQUIRE(fd >= 0);

int epoll_fd = epoll_create(1);
ATF_REQUIRE(epoll_fd >= 0);

struct epoll_event ee;
ee.events = 0;
ee.data.u64 = 0;

ATF_REQUIRE((fcntl(fd, F_GETFL) & O_NONBLOCK) != 0);

int err = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ee);
ATF_REQUIRE(err == 0);

ATF_REQUIRE((fcntl(fd, F_GETFL) & O_NONBLOCK) != 0);

ATF_REQUIRE(close(epoll_fd) == 0);
ATF_REQUIRE(close(fd) == 0);
}

ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, epoll__simple);
Expand Down Expand Up @@ -2161,6 +2186,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, epoll__epoll_pwait);
ATF_TP_ADD_TC(tp, epoll__cloexec);
ATF_TP_ADD_TC(tp, epoll__fcntl_fl);
ATF_TP_ADD_TC(tp, epoll__fcntl_issue49);

return atf_no_error();
}

0 comments on commit 3139d76

Please sign in to comment.