diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-02-17 18:28:53 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-02-18 02:51:47 +0100 |
commit | 9f5650aecb22a1d864b2c0b749910556795f1490 (patch) | |
tree | 62283b6837299eff161d62438372ec6d54d6b451 /src/shared/util.c | |
parent | ed7e5fe37d7e3392538844abadbb2903f4d2540f (diff) |
util: generalize code that checks whether PIDs are alive or unwaited for
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 4f3145b2bc..72b1e2f3c8 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -6045,7 +6045,9 @@ int namespace_enter(int pidns_fd, int mntns_fd, int root_fd) { return 0; } -bool pid_valid(pid_t pid) { +bool pid_is_unwaited(pid_t pid) { + /* Checks whether a PID is still valid at all, including a zombie */ + if (pid <= 0) return false; @@ -6055,6 +6057,21 @@ bool pid_valid(pid_t pid) { return errno != ESRCH; } +bool pid_is_alive(pid_t pid) { + int r; + + /* Checks whether a PID is still valid and not a zombie */ + + if (pid <= 0) + return false; + + r = get_process_state(pid); + if (r == -ENOENT || r == 'Z') + return false; + + return true; +} + int getpeercred(int fd, struct ucred *ucred) { socklen_t n = sizeof(struct ucred); struct ucred u; |