chiark / gitweb /
core: unify how we generate the prefix string when dumping unit state
[elogind.git] / src / core / service.c
index ace45e29ec021d9202565b8b712c5ae7dac166df..887b1c8514cfd35ed6e13ede49faeb1b05ee6719 100644 (file)
@@ -463,16 +463,14 @@ static int service_load(Unit *u) {
 }
 
 static void service_dump(Unit *u, FILE *f, const char *prefix) {
-
         ServiceExecCommand c;
         Service *s = SERVICE(u);
         const char *prefix2;
-        _cleanup_free_ char *p2 = NULL;
 
         assert(s);
 
-        p2 = strappend(prefix, "\t");
-        prefix2 = p2 ? p2 : prefix;
+        prefix = strempty(prefix);
+        prefix2 = strappenda(prefix, "\t");
 
         fprintf(f,
                 "%sService State: %s\n"
@@ -1699,6 +1697,10 @@ static int service_start(Unit *u) {
         s->main_pid_alien = false;
         s->forbid_restart = false;
 
+        free(s->status_text);
+        s->status_text = NULL;
+        s->status_errno = 0;
+
         service_enter_start_pre(s);
         return 0;
 }
@@ -2547,11 +2549,15 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us
 
 static int service_dispatch_watchdog(sd_event_source *source, usec_t usec, void *userdata) {
         Service *s = SERVICE(userdata);
+        char t[FORMAT_TIMESPAN_MAX];
 
         assert(s);
         assert(source == s->watchdog_event_source);
 
-        log_error_unit(UNIT(s)->id, "%s watchdog timeout!", UNIT(s)->id);
+        log_error_unit(UNIT(s)->id,
+                       "%s watchdog timeout (limit %s)!",
+                       UNIT(s)->id,
+                       format_timespan(t, sizeof(t), s->watchdog_usec, 1));
         service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_WATCHDOG);
 
         return 0;
@@ -2575,7 +2581,6 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
         }
 
         if (s->notify_access == NOTIFY_MAIN && pid != s->main_pid) {
-
                 if (s->main_pid != 0)
                         log_warning_unit(u->id, "%s: Got notification message from PID "PID_FMT", but reception only permitted for main PID "PID_FMT, u->id, pid, s->main_pid);
                 else
@@ -2584,14 +2589,10 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
         }
 
         /* Interpret MAINPID= */
-        if ((e = strv_find_prefix(tags, "MAINPID=")) &&
-            (s->state == SERVICE_START ||
-             s->state == SERVICE_START_POST ||
-             s->state == SERVICE_RUNNING ||
-             s->state == SERVICE_RELOAD)) {
-
+        e = strv_find_prefix(tags, "MAINPID=");
+        if (e && IN_SET(s->state, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD)) {
                 if (parse_pid(e + 8, &pid) < 0)
-                        log_warning_unit(u->id, "Failed to parse notification message %s", e);
+                        log_warning_unit(u->id, "Failed to parse MAINPID= field in notification message: %s", e);
                 else {
                         log_debug_unit(u->id, "%s: got %s", u->id, e);
                         service_set_main_pid(s, pid);
@@ -2642,7 +2643,7 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
         if (e) {
                 int status_errno;
 
-                if (safe_atoi(e + 6, &status_errno) < 0)
+                if (safe_atoi(e + 6, &status_errno) < 0 || status_errno < 0)
                         log_warning_unit(u->id, "Failed to parse ERRNO= field in notification message: %s", e);
                 else {
                         log_debug_unit(u->id, "%s: got %s", u->id, e);