summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2011-09-22 13:10:32 +0200
committerMichal Schmidt <mschmidt@redhat.com>2011-09-22 13:18:52 +0200
commit5375410bb2ed11a6a9e37063c0a551a7bf75338f (patch)
tree798885107ea0a396236d63217f593d8f4805f54a /src
parent0cdad5c0521fe87c4eef33a817f628bf3a9872c6 (diff)
service: warn if a service fails to write its PID file
Warn if a service promises to write a PID file (using 'PIDFile=' in the unit file or '# pidfile:' in SysV header), but fails to keep the promise. This warning will likely trigger also for the forking services with a racy daemonization, which exit the original process before the PID file is written.
Diffstat (limited to 'src')
-rw-r--r--src/service.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/service.c b/src/service.c
index a40e01b888..2b45ecb715 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1281,7 +1281,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
free(p2);
}
-static int service_load_pid_file(Service *s) {
+static int service_load_pid_file(Service *s, bool warn_if_missing) {
char *k;
int r;
pid_t pid;
@@ -1291,8 +1291,12 @@ static int service_load_pid_file(Service *s) {
if (!s->pid_file)
return -ENOENT;
- if ((r = read_one_line_file(s->pid_file, &k)) < 0)
+ if ((r = read_one_line_file(s->pid_file, &k)) < 0) {
+ if (warn_if_missing)
+ log_warning("Failed to read PID file %s after %s. The service might be broken.",
+ s->pid_file, service_state_to_string(s->state));
return r;
+ }
r = parse_pid(k, &pid);
free(k);
@@ -2604,7 +2608,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
/* Forking services may occasionally move to a new PID.
* As long as they update the PID file before exiting the old
* PID, they're fine. */
- if (service_load_pid_file(s) == 0)
+ if (service_load_pid_file(s, false) == 0)
return;
s->main_pid = 0;
@@ -2736,7 +2740,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
* START_POST script */
if (success) {
- service_load_pid_file(s);
+ service_load_pid_file(s, !s->exec_command[SERVICE_EXEC_START_POST]);
service_search_main_pid(s);
service_enter_start_post(s);
@@ -2747,7 +2751,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case SERVICE_START_POST:
if (success) {
- service_load_pid_file(s);
+ service_load_pid_file(s, true);
service_search_main_pid(s);
}
@@ -2757,7 +2761,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case SERVICE_RELOAD:
if (success) {
- service_load_pid_file(s);
+ service_load_pid_file(s, true);
service_search_main_pid(s);
}