summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-18 04:19:20 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-18 18:21:27 +0100
commitbf108e5541e2a3cbc6f0c59e93665eceb7a5ce05 (patch)
tree9cf3647427c0b9fb99a05b0fc48eedd0c0256015 /src/shared
parentf6613dd959a1ab49bf061555ada77903397569ad (diff)
service: watch main pid even in final states
In some circumstances, for example when start-up times out we immediately jump into the final state, at which point we still should try to watch the main pid so that the SIGCHLD allows us to quickly move into dead state.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c10
-rw-r--r--src/shared/util.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 2cf9fbe53e..f59897105a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6088,3 +6088,13 @@ int namespace_enter(int pidns_fd, int mntns_fd, int root_fd) {
return 0;
}
+
+bool pid_valid(pid_t pid) {
+ if (pid <= 0)
+ return false;
+
+ if (kill(pid, 0) >= 0)
+ return true;
+
+ return errno != ESRCH;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index ddb35181ab..3e0a6d5c1c 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -804,3 +804,5 @@ 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);