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 | |
parent | ed7e5fe37d7e3392538844abadbb2903f4d2540f (diff) |
util: generalize code that checks whether PIDs are alive or unwaited for
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 19 | ||||
-rw-r--r-- | src/shared/util.h | 3 |
2 files changed, 20 insertions, 2 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; diff --git a/src/shared/util.h b/src/shared/util.h index 7c88dad631..a41348e32e 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -858,7 +858,8 @@ int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int root_fd); -bool pid_valid(pid_t pid); +bool pid_is_alive(pid_t pid); +bool pid_is_unwaited(pid_t pid); int getpeercred(int fd, struct ucred *ucred); int getpeersec(int fd, char **ret); |