chiark / gitweb /
execute: improve exec_spawn() logging
[elogind.git] / service.c
index 7ed9783f796c2786fe7c402dc9df122efea3f8fb..e5a9658bcfa7784edef26acb0cf17f917998c194 100644 (file)
--- a/service.c
+++ b/service.c
@@ -157,7 +157,10 @@ static int sysv_chkconfig_order(Service *s) {
                 if (t->sysv_start_priority < 0)
                         continue;
 
-                if (s->sysv_has_lsb && t->sysv_has_lsb)
+                /* If both units have modern headers we don't care
+                 * about the priorities */
+                if ((!s->sysv_path || s->sysv_has_lsb) &&
+                    (!t->sysv_path || t->sysv_has_lsb))
                         continue;
 
                 if (t->sysv_start_priority < s->sysv_start_priority)
@@ -768,6 +771,16 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
                 prefix, kill_mode_to_string(s->kill_mode),
                 prefix, service_type_to_string(s->type));
 
+        if (s->control_pid > 0)
+                fprintf(f,
+                        "%sControl PID: %llu\n",
+                        prefix, (unsigned long long) s->control_pid);
+
+        if (s->main_pid > 0)
+                fprintf(f,
+                        "%sMain PID: %llu\n",
+                        prefix, (unsigned long long) s->main_pid);
+
         if (s->pid_file)
                 fprintf(f,
                         "%sPIDFile: %s\n",
@@ -829,7 +842,17 @@ static int service_load_pid_file(Service *s) {
         if ((unsigned long) (pid_t) p != p)
                 return -ERANGE;
 
-        s->main_pid = p;
+        if (kill((pid_t) p, 0) < 0 && errno != EPERM) {
+                log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.",
+                            (unsigned long long) p, s->pid_file);
+                return -ESRCH;
+        }
+
+        if ((r = unit_watch_pid(UNIT(s), (pid_t) p)) < 0)
+                /* FIXME: we need to do something here */
+                return r;
+
+        s->main_pid = (pid_t) p;
         s->main_pid_known = true;
 
         return 0;
@@ -968,6 +991,9 @@ static void service_set_state(Service *s, ServiceState state) {
             state == SERVICE_AUTO_RESTART)
                 service_notify_sockets(s);
 
+        if (old_state == state)
+                return;
+
         log_debug("%s changed %s → %s", unit_id(UNIT(s)), service_state_to_string(old_state), service_state_to_string(state));
 
         unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);