pidref: add new pidref_is_self() helper

This simply checks if the specified PidRef refers to the process we are
running in.

(In case you wonder why this is not a static inline: to avoid cyclic
header inclusion problems between pidref.h + process-util.h)
This commit is contained in:
Lennart Poettering
2023-10-18 14:39:33 +02:00
parent d7d748548b
commit a7a877697f
5 changed files with 13 additions and 4 deletions
+7
View File
@@ -263,6 +263,13 @@ int pidref_verify(const PidRef *pidref) {
return 1; /* We have a pidfd and it still points to the PID we have, hence all is *really* OK → return 1 */
}
bool pidref_is_self(const PidRef *pidref) {
if (!pidref)
return false;
return pidref->pid == getpid_cached();
}
static void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
siphash24_compress(&pidref->pid, sizeof(pidref->pid), state);
}