summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-22 15:38:52 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2022-11-23 00:54:23 +0100
commit0c14c45e5c00bbaed81566ace8f0d0c70cfe6392 (patch)
treeff5e3cdb85325f6927bde512838f15eabc1e2709 /src
parentMerge pull request #25485 from DaanDeMeyer/gpt-fix (diff)
downloadsystemd-0c14c45e5c00bbaed81566ace8f0d0c70cfe6392.tar.xz
systemd-0c14c45e5c00bbaed81566ace8f0d0c70cfe6392.zip
sd-event: reenable epoll_pwait2()
This reenables epoll_pwait2() use, i.e. undoes the effect of 39f756d3ae4765b8bf017567a12b8a4b358eaaf5. Instead of just reverting that, this PR will change things so that we strictly rely on glibc's new epoll_pwait2() wrapper (which was added earlier this year), and drop our own manual fallback syscall wrapper. That should nicely side-step any issues with correct syscall wrapping definitions (which on some arch seem not to be easy, given the sigset_t size final argument), by making this a glibc problem, not ours. Given that the only benefit this delivers are time-outs more granular than msec, it shouldn't really matter that we'll miss out on support for this on systems with older glibcs.
Diffstat (limited to 'src')
-rw-r--r--src/basic/missing_syscall.h38
-rw-r--r--src/basic/missing_syscall_def.h68
-rw-r--r--src/basic/missing_syscalls.py1
-rw-r--r--src/libsystemd/sd-event/sd-event.c15
4 files changed, 9 insertions, 113 deletions
diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h
index 6ad89da541..98cd037962 100644
--- a/src/basic/missing_syscall.h
+++ b/src/basic/missing_syscall.h
@@ -426,44 +426,6 @@ static inline int missing_close_range(int first_fd, int end_fd, unsigned flags)
/* ======================================================================= */
-#if !HAVE_EPOLL_PWAIT2
-
-/* Defined to be equivalent to the kernel's _NSIG_WORDS, i.e. the size of the array of longs that is
- * encapsulated by sigset_t. */
-#define KERNEL_NSIG_WORDS (64 / (sizeof(long) * 8))
-#define KERNEL_NSIG_BYTES (KERNEL_NSIG_WORDS * sizeof(long))
-
-struct epoll_event;
-
-static inline int missing_epoll_pwait2(
- int fd,
- struct epoll_event *events,
- int maxevents,
- const struct timespec *timeout,
- const sigset_t *sigset) {
-
-# if defined(__NR_epoll_pwait2) && HAVE_LINUX_TIME_TYPES_H
- if (timeout) {
- /* Convert from userspace timespec to kernel timespec */
- struct __kernel_timespec ts = {
- .tv_sec = timeout->tv_sec,
- .tv_nsec = timeout->tv_nsec,
- };
-
- return syscall(__NR_epoll_pwait2, fd, events, maxevents, &ts, sigset, sigset ? KERNEL_NSIG_BYTES : 0);
- } else
- return syscall(__NR_epoll_pwait2, fd, events, maxevents, NULL, sigset, sigset ? KERNEL_NSIG_BYTES : 0);
-# else
- errno = ENOSYS;
- return -1;
-# endif
-}
-
-# define epoll_pwait2 missing_epoll_pwait2
-#endif
-
-/* ======================================================================= */
-
#if !HAVE_MOUNT_SETATTR
#if !HAVE_STRUCT_MOUNT_ATTR
diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h
index 67cae7098d..402fdd00dc 100644
--- a/src/basic/missing_syscall_def.h
+++ b/src/basic/missing_syscall_def.h
@@ -246,74 +246,6 @@ assert_cc(__NR_copy_file_range == systemd_NR_copy_file_range);
# endif
#endif
-#ifndef __IGNORE_epoll_pwait2
-# if defined(__aarch64__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__alpha__)
-# define systemd_NR_epoll_pwait2 551
-# elif defined(__arc__) || defined(__tilegx__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__arm__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__i386__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__ia64__)
-# define systemd_NR_epoll_pwait2 1465
-# elif defined(__loongarch64)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__m68k__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(_MIPS_SIM)
-# if _MIPS_SIM == _MIPS_SIM_ABI32
-# define systemd_NR_epoll_pwait2 4441
-# elif _MIPS_SIM == _MIPS_SIM_NABI32
-# define systemd_NR_epoll_pwait2 6441
-# elif _MIPS_SIM == _MIPS_SIM_ABI64
-# define systemd_NR_epoll_pwait2 5441
-# else
-# error "Unknown MIPS ABI"
-# endif
-# elif defined(__hppa__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__powerpc__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__riscv)
-# if __riscv_xlen == 32
-# define systemd_NR_epoll_pwait2 441
-# elif __riscv_xlen == 64
-# define systemd_NR_epoll_pwait2 441
-# else
-# error "Unknown RISC-V ABI"
-# endif
-# elif defined(__s390__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__sparc__)
-# define systemd_NR_epoll_pwait2 441
-# elif defined(__x86_64__)
-# if defined(__ILP32__)
-# define systemd_NR_epoll_pwait2 (441 | /* __X32_SYSCALL_BIT */ 0x40000000)
-# else
-# define systemd_NR_epoll_pwait2 441
-# endif
-# elif !defined(missing_arch_template)
-# warning "epoll_pwait2() syscall number is unknown for your architecture"
-# endif
-
-/* may be an (invalid) negative number due to libseccomp, see PR 13319 */
-# if defined __NR_epoll_pwait2 && __NR_epoll_pwait2 >= 0
-# if defined systemd_NR_epoll_pwait2
-assert_cc(__NR_epoll_pwait2 == systemd_NR_epoll_pwait2);
-# endif
-# else
-# if defined __NR_epoll_pwait2
-# undef __NR_epoll_pwait2
-# endif
-# if defined systemd_NR_epoll_pwait2 && systemd_NR_epoll_pwait2 >= 0
-# define __NR_epoll_pwait2 systemd_NR_epoll_pwait2
-# endif
-# endif
-#endif
-
#ifndef __IGNORE_getrandom
# if defined(__aarch64__)
# define systemd_NR_getrandom 278
diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py
index 642d4d985d..5ccf02adec 100644
--- a/src/basic/missing_syscalls.py
+++ b/src/basic/missing_syscalls.py
@@ -9,7 +9,6 @@ SYSCALLS = [
'bpf',
'close_range',
'copy_file_range',
- 'epoll_pwait2',
'getrandom',
'memfd_create',
'mount_setattr',
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 27908a9abc..fa98c8946e 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -3969,15 +3969,18 @@ static int epoll_wait_usec(
usec_t timeout) {
int msec;
-#if 0
+ /* A wrapper that uses epoll_pwait2() if available, and falls back to epoll_wait() if not. */
+
+#if HAVE_EPOLL_PWAIT2
static bool epoll_pwait2_absent = false;
int r;
- /* A wrapper that uses epoll_pwait2() if available, and falls back to epoll_wait() if not.
- *
- * FIXME: this is temporarily disabled until epoll_pwait2() becomes more widely available.
- * See https://github.com/systemd/systemd/pull/18973 and
- * https://github.com/systemd/systemd/issues/19052. */
+ /* epoll_pwait2() was added to Linux 5.11 (2021-02-14) and to glibc in 2.35 (2022-02-03). In contrast
+ * to other syscalls we don't bother with our own fallback syscall wrappers on old libcs, since this
+ * is not that obvious to implement given the libc and kernel definitions differ in the last
+ * argument. Moreover, the only reason to use it is the more accurate time-outs (which is not a
+ * biggie), let's hence rely on glibc's definitions, and fallback to epoll_pwait() when that's
+ * missing. */
if (!epoll_pwait2_absent && timeout != USEC_INFINITY) {
r = epoll_pwait2(fd,