chiark / gitweb /
systemctl: highlight failed processes in systemctl status
authorLennart Poettering <lennart@poettering.net>
Thu, 20 Jan 2011 17:22:03 +0000 (18:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 20 Jan 2011 17:22:03 +0000 (18:22 +0100)
Makefile.am
src/exit-status.c
src/exit-status.h
src/mount.c
src/remount-api-vfs.c
src/service.c
src/socket.c
src/swap.c
src/systemctl.c
src/util.c
src/util.h

index b594b65387441338a35ee169e0f005b7c9230b02..351f1ce54d5e0ce873b0fe5d528e293663456174 100644 (file)
@@ -820,7 +820,8 @@ systemd_vconsole_setup_LDADD = \
 
 systemd_remount_api_vfs_SOURCES = \
        src/remount-api-vfs.c \
 
 systemd_remount_api_vfs_SOURCES = \
        src/remount-api-vfs.c \
-       src/mount-setup.c
+       src/mount-setup.c \
+       src/exit-status.c
 
 systemd_remount_api_vfs_CFLAGS = \
        $(AM_CFLAGS)
 
 systemd_remount_api_vfs_CFLAGS = \
        $(AM_CFLAGS)
index 4fed3c70a4f43391a4d9e4a83297e4a7088701f0..9b7c027b43b002714d6614c71a73e017623813dd 100644 (file)
@@ -20,6 +20,7 @@
 ***/
 
 #include <stdlib.h>
 ***/
 
 #include <stdlib.h>
+#include <sys/wait.h>
 
 #include "exit-status.h"
 
 
 #include "exit-status.h"
 
@@ -143,3 +144,31 @@ const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) {
 
         return NULL;
 }
 
         return NULL;
 }
+
+
+bool is_clean_exit(int code, int status) {
+
+        if (code == CLD_EXITED)
+                return status == 0;
+
+        /* If a daemon does not implement handlers for some of the
+         * signals that's not considered an unclean shutdown */
+        if (code == CLD_KILLED)
+                return
+                        status == SIGHUP ||
+                        status == SIGINT ||
+                        status == SIGTERM ||
+                        status == SIGPIPE;
+
+        return false;
+}
+
+bool is_clean_exit_lsb(int code, int status) {
+
+        if (is_clean_exit(code, status))
+                return true;
+
+        return
+                code == CLD_EXITED &&
+                (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
+}
index 178bdf6d616c7f9df053b89e2378b6994d645a6e..28f03a59117852e3da1cf84971912e5d1efb352a 100644 (file)
@@ -22,6 +22,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <stdbool.h>
+
 typedef enum ExitStatus {
         /* EXIT_SUCCESS defined by libc */
         /* EXIT_FAILURE defined by libc */
 typedef enum ExitStatus {
         /* EXIT_SUCCESS defined by libc */
         /* EXIT_FAILURE defined by libc */
@@ -75,4 +77,7 @@ typedef enum ExitStatusLevel {
 
 const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level);
 
 
 const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level);
 
+bool is_clean_exit(int code, int status);
+bool is_clean_exit_lsb(int code, int status);
+
 #endif
 #endif
index 08e99141b12f3abd59db826a9d5be40dcce1e849..f978a5467d2f542e76046f7292ecafa8168585b0 100644 (file)
@@ -36,6 +36,7 @@
 #include "dbus-mount.h"
 #include "special.h"
 #include "bus-errors.h"
 #include "dbus-mount.h"
 #include "special.h"
 #include "bus-errors.h"
+#include "exit-status.h"
 
 static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
         [MOUNT_DEAD] = UNIT_INACTIVE,
 
 static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
         [MOUNT_DEAD] = UNIT_INACTIVE,
index 8cdf7e875882009b771f3a5adcbdb68a0e27e406..5b1872833a5d5bc4e35ef95be85367fa908db53d 100644 (file)
@@ -31,6 +31,7 @@
 #include "util.h"
 #include "set.h"
 #include "mount-setup.h"
 #include "util.h"
 #include "set.h"
 #include "mount-setup.h"
+#include "exit-status.h"
 
 /* Goes through /etc/fstab and remounts all API file systems, applying
  * options that are in /etc/fstab that systemd might not have
 
 /* Goes through /etc/fstab and remounts all API file systems, applying
  * options that are in /etc/fstab that systemd might not have
index 431bccc4e1ad5bcb0ec7bd99310f70df2ad22f6b..4115e52901fd4e22cfb8101ff8f14e1203d0cf96 100644 (file)
@@ -34,6 +34,7 @@
 #include "dbus-service.h"
 #include "special.h"
 #include "bus-errors.h"
 #include "dbus-service.h"
 #include "special.h"
 #include "bus-errors.h"
+#include "exit-status.h"
 
 #define COMMENTS "#;\n"
 #define NEWLINES "\n\r"
 
 #define COMMENTS "#;\n"
 #define NEWLINES "\n\r"
index 7dc205abde362a1d256a0e0a930e3881a9373ca0..3bb8862ca9bb39e1a939929f912803585ec2f8ba 100644 (file)
@@ -41,6 +41,7 @@
 #include "special.h"
 #include "bus-errors.h"
 #include "label.h"
 #include "special.h"
 #include "bus-errors.h"
 #include "label.h"
+#include "exit-status.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
index 6ab99d5712f09d74058de5abdd286567dfbb1787..23a98dd63f12070e309095f8819d53d6cd97f409 100644 (file)
@@ -36,6 +36,7 @@
 #include "dbus-swap.h"
 #include "special.h"
 #include "bus-errors.h"
 #include "dbus-swap.h"
 #include "special.h"
 #include "bus-errors.h"
+#include "exit-status.h"
 
 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = UNIT_INACTIVE,
 
 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = UNIT_INACTIVE,
index f93f2aa480b043150254f4e3ed06ddeacc11f912..fb3430048cd7f7aef5e9234832774513731f543a 100644 (file)
@@ -1847,15 +1847,31 @@ static void print_status_info(UnitStatusInfo *i) {
 
         LIST_FOREACH(exec, p, i->exec) {
                 char *t;
 
         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, " ");
 
                 /* Only show exited processes here */
                 if (p->code == 0)
                         continue;
 
                 t = strv_join(p->argv, " ");
-                printf("\t Process: %u %s=%s (code=%s, ", p->pid, p->name, strna(t), sigchld_code_to_string(p->code));
+                printf("\t Process: %u %s=%s ", p->pid, p->name, strna(t));
                 free(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;
 
                 if (p->code == CLD_EXITED) {
                         const char *c;
 
@@ -1870,7 +1886,10 @@ static void print_status_info(UnitStatusInfo *i) {
 
                 } else
                         printf("signal=%s", signal_to_string(p->status));
 
                 } 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 &&
 
                 if (i->main_pid == p->pid &&
                     i->start_timestamp == p->start_timestamp &&
index 30a3b058fce07cf9cc1ad142509248482b201655..d3876ded5b154ae17e6059139bd8d3bb472740de 100644 (file)
@@ -2617,33 +2617,6 @@ int make_null_stdio(void) {
         return make_stdio(null_fd);
 }
 
         return make_stdio(null_fd);
 }
 
-bool is_clean_exit(int code, int status) {
-
-        if (code == CLD_EXITED)
-                return status == 0;
-
-        /* If a daemon does not implement handlers for some of the
-         * signals that's not considered an unclean shutdown */
-        if (code == CLD_KILLED)
-                return
-                        status == SIGHUP ||
-                        status == SIGINT ||
-                        status == SIGTERM ||
-                        status == SIGPIPE;
-
-        return false;
-}
-
-bool is_clean_exit_lsb(int code, int status) {
-
-        if (is_clean_exit(code, status))
-                return true;
-
-        return
-                code == CLD_EXITED &&
-                (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED);
-}
-
 bool is_device_path(const char *path) {
 
         /* Returns true on paths that refer to a device, either in
 bool is_device_path(const char *path) {
 
         /* Returns true on paths that refer to a device, either in
index e9ad881e9cd50c356e019dae532296061dff5b2c..c8cae703a2bc8e6bce46e6050af05b77bfdf4e45 100644 (file)
@@ -267,9 +267,6 @@ char *format_timespan(char *buf, size_t l, usec_t t);
 int make_stdio(int fd);
 int make_null_stdio(void);
 
 int make_stdio(int fd);
 int make_null_stdio(void);
 
-bool is_clean_exit(int code, int status);
-bool is_clean_exit_lsb(int code, int status);
-
 unsigned long long random_ull(void);
 
 #define DEFINE_STRING_TABLE_LOOKUP(name,type)                           \
 unsigned long long random_ull(void);
 
 #define DEFINE_STRING_TABLE_LOOKUP(name,type)                           \