Michal Schmidt e43452
From 3fdac700a322217421675774e25cfd5cb09c2dd2 Mon Sep 17 00:00:00 2001
Michal Schmidt e43452
From: Michal Schmidt <mschmidt@redhat.com>
Michal Schmidt e43452
Date: Thu, 10 Nov 2011 09:55:47 +0100
Michal Schmidt f1996e
Subject: [PATCH] service: don't warn if the pidfile still exists after
Michal Schmidt f1996e
 SIGCHLD
Michal Schmidt e43452
Michal Schmidt e43452
A service that drops its privileges may not be able to remove it when it
Michal Schmidt e43452
exits. The stale pidfile is not a problem as long as the service
Michal Schmidt e43452
carefully recognizes it on its next start.
Michal Schmidt e43452
Michal Schmidt e43452
systemd would produce a warning after the service exits:
Michal Schmidt e43452
  PID ... read from file ... does not exist. Your service or init
Michal Schmidt e43452
  script might be broken.
Michal Schmidt e43452
Michal Schmidt e43452
Silence the warning in this case. Still warn if this error is detected
Michal Schmidt e43452
when loading the pidfile after service start.
Michal Schmidt e43452
Michal Schmidt e43452
Noticed by Miroslav Lichvar in
Michal Schmidt e43452
 https://bugzilla.redhat.com/show_bug.cgi?id=752396
Michal Schmidt e43452
(cherry picked from commit c5419d4239ceb4c3bd0263a0a810cf24a072b3c0)
Michal Schmidt e43452
---
Michal Schmidt e43452
 src/service.c |    9 +++++----
Michal Schmidt e43452
 1 files changed, 5 insertions(+), 4 deletions(-)
Michal Schmidt e43452
Michal Schmidt e43452
diff --git a/src/service.c b/src/service.c
Michal Schmidt e43452
index e64d289..d51445e 100644
Michal Schmidt e43452
--- a/src/service.c
Michal Schmidt e43452
+++ b/src/service.c
Michal Schmidt e43452
@@ -1282,7 +1282,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
Michal Schmidt e43452
         free(p2);
Michal Schmidt e43452
 }
Michal Schmidt e43452
 
Michal Schmidt e43452
-static int service_load_pid_file(Service *s, bool warn_if_missing) {
Michal Schmidt e43452
+static int service_load_pid_file(Service *s, bool may_warn) {
Michal Schmidt e43452
         char *k;
Michal Schmidt e43452
         int r;
Michal Schmidt e43452
         pid_t pid;
Michal Schmidt e43452
@@ -1293,7 +1293,7 @@ static int service_load_pid_file(Service *s, bool warn_if_missing) {
Michal Schmidt e43452
                 return -ENOENT;
Michal Schmidt e43452
 
Michal Schmidt e43452
         if ((r = read_one_line_file(s->pid_file, &k)) < 0) {
Michal Schmidt e43452
-                if (warn_if_missing)
Michal Schmidt e43452
+                if (may_warn)
Michal Schmidt e43452
                         log_warning("Failed to read PID file %s after %s. The service might be broken.",
Michal Schmidt e43452
                                     s->pid_file, service_state_to_string(s->state));
Michal Schmidt e43452
                 return r;
Michal Schmidt e43452
@@ -1306,8 +1306,9 @@ static int service_load_pid_file(Service *s, bool warn_if_missing) {
Michal Schmidt e43452
                 return r;
Michal Schmidt e43452
 
Michal Schmidt e43452
         if (kill(pid, 0) < 0 && errno != EPERM) {
Michal Schmidt e43452
-                log_warning("PID %lu read from file %s does not exist. Your service or init script might be broken.",
Michal Schmidt e43452
-                            (unsigned long) pid, s->pid_file);
Michal Schmidt e43452
+                if (may_warn)
Michal Schmidt e43452
+                        log_warning("PID %lu read from file %s does not exist. Your service or init script might be broken.",
Michal Schmidt e43452
+                                    (unsigned long) pid, s->pid_file);
Michal Schmidt e43452
                 return -ESRCH;
Michal Schmidt e43452
         }
Michal Schmidt e43452