Skip to contentSkip to conversation

clean up SYS_signalfd

PATCH In review Laszlo Ersek 2 participants 4 messages Jan 21, 2015

lore
Share & tools
lore
#0 lore raw

cover clean up SYS_signalfd

SYS_signalfd is deprecated and absent on some Linux systems that do support signalfd().

Also, in 2015 the signalfd() libc function should be available wherever the underlying syscall(s) are available.

Drop SYS_signalfd and check for & use signalfd() directly.

Laszlo Ersek (2):
qemu_signalfd_available(): remove function due to lack of callers signalfd(): modernize detection and use

 configure               | 11 ++++++++---
 include/qemu/compatfd.h |  1 -
 util/compatfd.c         | 24 ++----------------------
 3 files changed, 10 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 qemu_signalfd_available(): remove function due to lack of callers

Noone calls qemu_signalfd_available(), let's remove it.

---
 include/qemu/compatfd.h |  1 -
 util/compatfd.c         | 19 -------------------
 2 files changed, 20 deletions(-)
include/qemu/compatfd.h +0 -1
index 6b04877..fc37915 100644
@@ -39,6 +39,5 @@ struct qemu_signalfd_siginfo {
 };
 
 int qemu_signalfd(const sigset_t *mask);
-bool qemu_signalfd_available(void);
 
 #endif
util/compatfd.c +0 -19
index 341ada6..e857150 100644
@@ -108,22 +108,3 @@ int qemu_signalfd(const sigset_t *mask)
 
     return qemu_signalfd_compat(mask);
 }
-
-bool qemu_signalfd_available(void)
-{
-#ifdef CONFIG_SIGNALFD
-    sigset_t mask;
-    int fd;
-    bool ok;
-    sigemptyset(&mask);
-    errno = 0;
-    fd = syscall(SYS_signalfd, -1, &mask, _NSIG / 8);
-    ok = (errno != ENOSYS);
-    if (fd >= 0) {
-        close(fd);
-    }
-    return ok;
-#else
-    return false;
-#endif
-}
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 signalfd(): modernize detection and use

In reply to Laszlo Ersek

qemu_signalfd() provides the (effects of the) Linux signalfd() syscall on platforms that lack it. However, the check for the availability of signalfd() in configure, and its use in qemu_signalfd() when it *is* available, are seriously outdated (they date back to 2010-2011).

To wit, the SYS_signalfd-based check in configure can actually fail on at least modern aarch64 Linux systems that *do* have signalfd(). (SYS_signalfd is deprecated and has been replaced by SYS_signalfd4 (note the "4"). The signalfd() libc function selects the appropriate system call.)

We should consider signalfd() accessible as a first class libc function on platforms that support it. Modernize the related parts in configure and "util/compatfd.c" (so that we end up with something similar to eventfd()'s detection).

---
 configure       | 11 ++++++++---
 util/compatfd.c |  5 ++---
 2 files changed, 10 insertions(+), 6 deletions(-)
configure +8 -3
index 5ea1014..de0d21c 100755
@@ -3280,10 +3280,15 @@ fi
 # signalfd probe
 signalfd="no"
 cat > $TMPC << EOF
-#include <unistd.h>
-#include <sys/syscall.h>
+#include <sys/signalfd.h>
 #include <signal.h>
-int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
+int main(void)
+{
+    sigset_t s;
+
+    sigfillset(&s);
+    return signalfd(-1, &s, SFD_CLOEXEC);
+}
 EOF
 
 if compile_prog "" "" ; then
util/compatfd.c +2 -3
index e857150..7983391 100644
@@ -17,7 +17,7 @@
 #include "qemu/compatfd.h"
 #include "qemu/thread.h"
 
-#include <sys/syscall.h>
+#include <sys/signalfd.h>
 
 struct sigfd_compat_info
 {
@@ -99,9 +99,8 @@ int qemu_signalfd(const sigset_t *mask)
 #if defined(CONFIG_SIGNALFD)
     int ret;
 
-    ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
+    ret = signalfd(-1, mask, SFD_CLOEXEC);
     if (ret != -1) {
-        qemu_set_cloexec(ret);
         return ret;
     }
 #endif
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Laszlo Ersek
Quoted 8 lines · Laszlo Ersek

SYS_signalfd is deprecated and absent on some Linux systems that do support signalfd().

Also, in 2015 the signalfd() libc function should be available wherever the underlying syscall(s) are available.

Drop SYS_signalfd and check for & use signalfd() directly.

Quoted 8 lines

Laszlo Ersek (2):
qemu_signalfd_available(): remove function due to lack of callers signalfd(): modernize detection and use

 configure               | 11 ++++++++---
 include/qemu/compatfd.h |  1 -
 util/compatfd.c         | 24 ++----------------------
 3 files changed, 10 insertions(+), 26 deletions(-)

I suspect this will stop using signalfd on RHEL5. I wouldn't weep, but it's worth pointing it out.

Paolo