mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
This compares two PidRef structures via the pid_t field. Ideally we'd do a stricter comparison here, that is safe towards PID reuse, but so far the pidfd API lacks suitable mechanisms for that, hence do the best we can do.
43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include "macro.h"
|
|
|
|
/* An embeddable structure carrying a reference to a process. Supposed to be used when tracking processes continuously. */
|
|
typedef struct PidRef {
|
|
pid_t pid; /* always valid */
|
|
int fd; /* only valid if pidfd are available in the kernel, and we manage to get an fd */
|
|
} PidRef;
|
|
|
|
#define PIDREF_NULL (PidRef) { .fd = -EBADF }
|
|
|
|
static inline bool pidref_is_set(const PidRef *pidref) {
|
|
return pidref && pidref->pid > 0;
|
|
}
|
|
|
|
static inline bool pidref_equal(const PidRef *a, const PidRef *b) {
|
|
|
|
if (pidref_is_set(a)) {
|
|
if (!pidref_is_set(b))
|
|
return false;
|
|
|
|
return a->pid == b->pid;
|
|
}
|
|
|
|
return !pidref_is_set(b);
|
|
}
|
|
|
|
int pidref_set_pid(PidRef *pidref, pid_t pid);
|
|
int pidref_set_pidstr(PidRef *pidref, const char *pid);
|
|
int pidref_set_pidfd(PidRef *pidref, int fd);
|
|
int pidref_set_pidfd_take(PidRef *pidref, int fd); /* takes ownership of the passed pidfd on success*/
|
|
int pidref_set_pidfd_consume(PidRef *pidref, int fd); /* takes ownership of the passed pidfd in both success and failure */
|
|
|
|
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)
|