]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidref: add sigqueue() helper
authorLennart Poettering <lennart@poettering.net>
Sun, 10 Sep 2023 14:17:35 +0000 (16:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 18 Sep 2023 17:08:09 +0000 (19:08 +0200)
src/basic/pidref.c
src/basic/pidref.h

index f41460938c1b96c7ae7af6376e738ba716b36a00..e1ad697af0cc8309b1e2cab82d5bb33e60728290 100644 (file)
@@ -6,6 +6,7 @@
 #include "parse-util.h"
 #include "pidref.h"
 #include "process-util.h"
+#include "signal-util.h"
 
 int pidref_set_pid(PidRef *pidref, pid_t pid) {
         int fd;
@@ -143,3 +144,30 @@ int pidref_kill_and_sigcont(PidRef *pidref, int sig) {
 
         return 0;
 }
+
+int pidref_sigqueue(PidRef *pidref, int sig, int value) {
+
+        if (!pidref)
+                return -ESRCH;
+
+        if (pidref->fd >= 0) {
+                siginfo_t si;
+
+                /* We can't use structured initialization here, since the structure contains various unions
+                 * and these fields lie in overlapping (carefully aligned) unions that LLVM is allergic to
+                 * allow assignments to */
+                zero(si);
+                si.si_signo = sig;
+                si.si_code = SI_QUEUE;
+                si.si_pid = getpid_cached();
+                si.si_uid = getuid();
+                si.si_value.sival_int = value;
+
+                return RET_NERRNO(pidfd_send_signal(pidref->fd, sig, &si, 0));
+        }
+
+        if (pidref->pid > 0)
+                return RET_NERRNO(sigqueue(pidref->pid, sig, (const union sigval) { .sival_int = value }));
+
+        return -ESRCH;
+}
index 2411e510f13378d90460417535df9ac937ca2d92..6998a865e7fd65ebe83e6f7afcef90a978e867f2 100644 (file)
@@ -25,5 +25,6 @@ void pidref_done(PidRef *pidref);
 
 int pidref_kill(PidRef *pidref, int sig);
 int pidref_kill_and_sigcont(PidRef *pidref, int sig);
+int pidref_sigqueue(PidRef *pidfref, int sig, int value);
 
 #define TAKE_PIDREF(p) TAKE_GENERIC((p), PidRef, PIDREF_NULL)