]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/pidref.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 /* An embeddable structure carrying a reference to a process. Supposed to be used when tracking processes continuously. */
7 typedef struct PidRef
{
8 pid_t pid
; /* always valid */
9 int fd
; /* only valid if pidfd are available in the kernel, and we manage to get an fd */
12 #define PIDREF_NULL (PidRef) { .fd = -EBADF }
14 static inline bool pidref_is_set(const PidRef
*pidref
) {
15 return pidref
&& pidref
->pid
> 0;
18 static inline bool pidref_equal(const PidRef
*a
, const PidRef
*b
) {
20 if (pidref_is_set(a
)) {
21 if (!pidref_is_set(b
))
24 return a
->pid
== b
->pid
;
27 return !pidref_is_set(b
);
30 int pidref_set_pid(PidRef
*pidref
, pid_t pid
);
31 int pidref_set_pidstr(PidRef
*pidref
, const char *pid
);
32 int pidref_set_pidfd(PidRef
*pidref
, int fd
);
33 int pidref_set_pidfd_take(PidRef
*pidref
, int fd
); /* takes ownership of the passed pidfd on success*/
34 int pidref_set_pidfd_consume(PidRef
*pidref
, int fd
); /* takes ownership of the passed pidfd in both success and failure */
36 void pidref_done(PidRef
*pidref
);
38 int pidref_kill(PidRef
*pidref
, int sig
);
39 int pidref_kill_and_sigcont(PidRef
*pidref
, int sig
);
40 int pidref_sigqueue(PidRef
*pidfref
, int sig
, int value
);
42 #define TAKE_PIDREF(p) TAKE_GENERIC((p), PidRef, PIDREF_NULL)