diff options
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); |