]> granicus.if.org Git - psmisc/commitdiff
killall: use kill if pidfd_send_signal() fails
authorCraig Small <csmall@dropbear.xyz>
Mon, 18 Jul 2022 10:16:42 +0000 (20:16 +1000)
committerCraig Small <csmall@dropbear.xyz>
Mon, 18 Jul 2022 10:16:42 +0000 (20:16 +1000)
The pidfd_send_signal() system call appeared in Linux 5.1
If psmisc is build on a system before then, or a non-Linux
system, then kill() is used instead. However if psmisc is
built on a Linux >= 5.1 system but run on a < 5.1 Linux
system the system call fails and killall doesn't work.

The fix, as proposed by Peter T. Breuer, is to try
pidfd_send_signal() and if the return value is < 0 and
errno is ENOSYS then we know at runtime the system call
failed and we fall through to trusty old kill().

Note, this means that killall on systems below 5.1 still
have the race PID condition that the pidfd calls fix.

References:
 https://bugs.debian.org/1015228

ChangeLog
src/killall.c

index ed9fb6832460bcd1211a663a0171239402137f6a..d539bc88847a91a95357e19554b6b3c174a5e2ac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 Changes in NEXT
 ===============
         * buildsys: Fix DEJAGNU work-around Debian #1015089
+       * killall: Use kill if pidfd_send_signal fails Debian #1015228
 
 Changes in 23.5
 ===============
index 78930c853d8d54b9eced43512847ad766a1c96ee..f573cfec34e6073d736d14b1a17a7796cd02a927 100644 (file)
@@ -326,7 +326,12 @@ my_send_signal(
 {
 #ifdef __NR_pidfd_send_signal
     if (pid > 0) /* Not PGID */
-        return syscall(__NR_pidfd_send_signal, pidfd, sig, NULL, 0);
+    {
+       int ret = syscall(__NR_pidfd_send_signal, pidfd, sig, NULL, 0);
+       if (ret >= 0 || errno != ENOSYS)
+           return ret;
+       // fall through if no such syscall
+    }
 #endif
     return kill(pid, sig);
 }