|
47 | 47 | #endif |
48 | 48 | #elif defined(__linux__) |
49 | 49 | #include <sys/epoll.h> |
50 | | - |
51 | | -#include <linux/version.h> |
52 | 50 | #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. */ |
56 | 53 | #else |
57 | 54 | #define USE_PPOLL |
58 | 55 | #endif |
@@ -148,9 +145,6 @@ struct eloop { |
148 | 145 | bool exitnow; |
149 | 146 | bool events_need_setup; |
150 | 147 | bool events_invalid; |
151 | | -#ifdef HAVE_EPOLL_PWAIT2 |
152 | | - bool epoll_pwait2_nosys; |
153 | | -#endif |
154 | 148 | }; |
155 | 149 |
|
156 | 150 | #ifdef HAVE_REALLOCARRAY |
@@ -944,36 +938,22 @@ eloop_run_epoll(struct eloop *eloop, const struct timespec *ts) |
944 | 938 | unsigned short events; |
945 | 939 |
|
946 | 940 | /* epoll does not work with zero events */ |
947 | | - if (eloop->nfds == 0) { |
| 941 | + if (eloop->nfds == 0) |
948 | 942 | 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 { |
963 | 944 | int timeout; |
964 | 945 |
|
965 | | -#ifdef HAVE_EPOLL_PWAIT2 |
966 | | - epoll_pwait2_nosys: |
967 | | -#endif |
968 | 946 | 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))) |
973 | 952 | timeout = INT_MAX; |
974 | 953 | 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); |
977 | 957 | } else |
978 | 958 | timeout = -1; |
979 | 959 |
|
|
0 commit comments