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:
parent
7901288ab1
commit
a0d1659c23
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user