Skip to content

Commit 4d41f7d

Browse files
committed
eloop: remove epoll_pwait2 support
It's just not there on musl, detecting it at compile time is hit and miss on glibc due to mismatched kernel headers.
1 parent 8880b8a commit 4d41f7d

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

src/eloop.c

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@
4747
#endif
4848
#elif defined(__linux__)
4949
#include <sys/epoll.h>
50-
51-
#include <linux/version.h>
5250
#define USE_EPOLL
53-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
54-
#define HAVE_EPOLL_PWAIT2
55-
#endif
51+
/* musl does not support epoll_wait2 and some distros
52+
* mismatch headers vs actual kernel so it's too problematic. */
5653
#else
5754
#define USE_PPOLL
5855
#endif
@@ -148,9 +145,6 @@ struct eloop {
148145
bool exitnow;
149146
bool events_need_setup;
150147
bool events_invalid;
151-
#ifdef HAVE_EPOLL_PWAIT2
152-
bool epoll_pwait2_nosys;
153-
#endif
154148
};
155149

156150
#ifdef HAVE_REALLOCARRAY
@@ -944,36 +938,22 @@ eloop_run_epoll(struct eloop *eloop, const struct timespec *ts)
944938
unsigned short events;
945939

946940
/* epoll does not work with zero events */
947-
if (eloop->nfds == 0) {
941+
if (eloop->nfds == 0)
948942
n = ppoll(NULL, 0, ts, &eloop->sigset);
949-
#ifdef HAVE_EPOLL_PWAIT2
950-
} else if (!eloop->epoll_pwait2_nosys) {
951-
/* Many linux distros are dumb in shipping newer
952-
* kernel headers than the target kernel they are using.
953-
* So we jump through this stupid hoop and have to write
954-
* more complex code. */
955-
n = epoll_pwait2(eloop->fd, eloop->fds, (int)eloop->nfds, ts,
956-
&eloop->sigset);
957-
if (n == -1 && errno == ENOSYS) {
958-
eloop->epoll_pwait2_nosys = true;
959-
goto epoll_pwait2_nosys;
960-
}
961-
#endif
962-
} else {
943+
else {
963944
int timeout;
964945

965-
#ifdef HAVE_EPOLL_PWAIT2
966-
epoll_pwait2_nosys:
967-
#endif
968946
if (ts != NULL) {
969-
if (ts->tv_sec > INT_MAX / 1000 ||
970-
(ts->tv_sec == INT_MAX / 1000 &&
971-
((ts->tv_nsec + 999999) / 1000000 >
972-
INT_MAX % 1000000)))
947+
if (ts->tv_sec > INT_MAX / MSEC_PER_SEC ||
948+
(ts->tv_sec == INT_MAX / MSEC_PER_SEC &&
949+
((ts->tv_nsec + (NSEC_PER_MSEC - 1)) /
950+
NSEC_PER_MSEC >
951+
INT_MAX % NSEC_PER_MSEC)))
973952
timeout = INT_MAX;
974953
else
975-
timeout = (int)(ts->tv_sec * 1000 +
976-
(ts->tv_nsec + 999999) / 1000000);
954+
timeout = (int)(ts->tv_sec * MSEC_PER_SEC +
955+
(ts->tv_nsec + (NSEC_PER_MSEC - 1)) /
956+
NSEC_PER_MSEC);
977957
} else
978958
timeout = -1;
979959

0 commit comments

Comments
 (0)