chiark / gitweb /
systemctl: highlight failed processes in systemctl status
[elogind.git] / src / systemctl.c
index 2c8c2cf61d5165036beffe54ec8784a67dc0a2e1..fb3430048cd7f7aef5e9234832774513731f543a 100644 (file)
@@ -1615,6 +1615,8 @@ finish:
 }
 
 typedef struct ExecStatusInfo {
+        char *name;
+
         char *path;
         char **argv;
 
@@ -1632,6 +1634,7 @@ typedef struct ExecStatusInfo {
 static void exec_status_info_free(ExecStatusInfo *i) {
         assert(i);
 
+        free(i->name);
         free(i->path);
         strv_free(i->argv);
         free(i);
@@ -1844,15 +1847,31 @@ static void print_status_info(UnitStatusInfo *i) {
 
         LIST_FOREACH(exec, p, i->exec) {
                 char *t;
+                bool good;
 
                 /* Only show exited processes here */
                 if (p->code == 0)
                         continue;
 
                 t = strv_join(p->argv, " ");
-                printf("\t Process: %u (%s, code=%s, ", p->pid, strna(t), sigchld_code_to_string(p->code));
+                printf("\t Process: %u %s=%s ", p->pid, p->name, strna(t));
                 free(t);
 
+#ifdef HAVE_SYSV_COMPAT
+                if (i->is_sysv)
+                        good = is_clean_exit_lsb(p->code, p->status);
+                else
+#endif
+                        good = is_clean_exit(p->code, p->status);
+
+                if (!good) {
+                        on = ansi_highlight(true);
+                        off = ansi_highlight(false);
+                } else
+                        on = off = "";
+
+                printf("%s(code=%s, ", on, sigchld_code_to_string(p->code));
+
                 if (p->code == CLD_EXITED) {
                         const char *c;
 
@@ -1867,7 +1886,10 @@ static void print_status_info(UnitStatusInfo *i) {
 
                 } else
                         printf("signal=%s", signal_to_string(p->status));
-                printf(")\n");
+
+                printf(")%s\n", off);
+
+                on = off = NULL;
 
                 if (i->main_pid == p->pid &&
                     i->start_timestamp == p->start_timestamp &&
@@ -2083,6 +2105,11 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
                                 if (!(info = new0(ExecStatusInfo, 1)))
                                         return -ENOMEM;
 
+                                if (!(info->name = strdup(name))) {
+                                        free(info);
+                                        return -ENOMEM;
+                                }
+
                                 if ((r = exec_status_info_deserialize(&sub, info)) < 0) {
                                         free(info);
                                         return r;