diff options
author | Luca Boccassi <bluca@debian.org> | 2023-01-20 13:13:22 +0100 |
---|---|---|
committer | Luca Boccassi <bluca@debian.org> | 2023-01-20 13:18:05 +0100 |
commit | f840c7d58dcd39fa98a887c50a9be5c35dbb599f (patch) | |
tree | 8a7a0f943f605e1268ff58a3a330449f0286336e /src/basic/process-util.c | |
parent | Merge pull request #26105 from yuwata/network-config-parse-address-make-prefi... (diff) | |
download | systemd-f840c7d58dcd39fa98a887c50a9be5c35dbb599f.tar.xz systemd-f840c7d58dcd39fa98a887c50a9be5c35dbb599f.zip |
process-util: add helper to verify a pid via its pidfd
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r-- | src/basic/process-util.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c index fa00c962ab..70aa15f060 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1456,6 +1456,20 @@ int pidfd_get_pid(int fd, pid_t *ret) { return parse_pid(p, ret); } +int pidfd_verify_pid(int pidfd, pid_t pid) { + pid_t current_pid; + int r; + + assert(pidfd >= 0); + assert(pid > 0); + + r = pidfd_get_pid(pidfd, ¤t_pid); + if (r < 0) + return r; + + return current_pid != pid ? -ESRCH : 0; +} + static int rlimit_to_nice(rlim_t limit) { if (limit <= 1) return PRIO_MAX-1; /* i.e. 19 */ |