From 3139d763d9b5eb296532db6672bd3522866b5dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kokem=C3=BCller?= Date: Sat, 8 Jun 2024 12:47:29 +0200 Subject: [PATCH] fix issue 49 --- src/epollfd_ctx.c | 4 ++-- test/epoll-test.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/epollfd_ctx.c b/src/epollfd_ctx.c index 4be130d..0db5b01 100644 --- a/src/epollfd_ctx.c +++ b/src/epollfd_ctx.c @@ -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; diff --git a/test/epoll-test.c b/test/epoll-test.c index 4d06f22..f53ee97 100644 --- a/test/epoll-test.c +++ b/test/epoll-test.c @@ -2114,6 +2114,31 @@ ATF_TC_BODY_FD_LEAKCHECK(epoll__fcntl_fl, tcptr) #endif } +// Test adapted from . +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); @@ -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(); }