1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

pidref: add sigqueue() helper

This commit is contained in:
Lennart Poettering 2023-09-10 16:17:35 +02:00
parent 7901288ab1
commit a0d1659c23
2 changed files with 29 additions and 0 deletions

View 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;
}

View 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)