dinitctl: show if service was skipped or failed.
authorDavin McCall <davmac@davmac.org>
Fri, 22 Jun 2018 08:57:21 +0000 (09:57 +0100)
committerDavin McCall <davmac@davmac.org>
Fri, 22 Jun 2018 08:57:21 +0000 (09:57 +0100)
Also update documentation accordingly.

doc/manpages/dinitctl.8
src/control.cc
src/dinitctl.cc

index 05992b7c13cca89ffe5ccf3b934b16ef0a05ee9d..dc77cc423e01882455dee443fd7814c915207949 100644 (file)
@@ -92,7 +92,13 @@ displayed:
 .fi
 
 The << and >> symbols represent a transition state (starting and stopping respectively); curly braces
-indicate the desired state (left: started, right: stopped).
+indicate the desired state (left: started, right: stopped). An 's' in place of '+' means that service
+startup was skipped (possible only if the service is configured as skippable). An 'X' in place of '-'
+means that the service failed to start, or that the service process unexpectedly terminated with an
+error status or signal while running.
+
+Additional information, if available, will be printed after the service name: whether the service owns,
+or is waiting to acquire, the console; the process ID; the exit status or signal that caused termination.
 .RE
 .TP
 \fBshutdown\fR
index 7f84e2e654cddbe7b25dddfeaddfaf8371b1d76f..8373daa376f927af151a68fc8d82ebea0d2c5ea7 100644 (file)
@@ -334,6 +334,7 @@ bool control_conn_t::list_services()
             
             char b0 = sptr->is_waiting_for_console() ? 1 : 0;
             b0 |= sptr->has_console() ? 2 : 0;
+            b0 |= sptr->was_start_skipped() ? 4 : 0;
             pkt_buf[4] = b0;
             pkt_buf[5] = static_cast<char>(sptr->get_stop_reason());
 
index 1bf06f771ce10821869d4223abe789cec7a87e6a..17dc9d04d70676e479caa4bde8092535308be128 100644 (file)
@@ -547,8 +547,9 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
         int console_flags = rbuffer[4];
         bool has_console = (console_flags & 2) != 0;
         bool waiting_console = (console_flags & 1) != 0;
+        bool was_skipped = (console_flags & 4) != 0;
 
-        // stopped_reason_t stop_reason = static_cast<stopped_reason_t>(rbuffer[5]);
+        stopped_reason_t stop_reason = static_cast<stopped_reason_t>(rbuffer[5]);
 
         pid_t service_pid;
         int exit_status;
@@ -570,7 +571,12 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
         cout << "[";
 
         cout << (target  == service_state_t::STARTED ? "{" : " ");
-        cout << (current == service_state_t::STARTED ? "+" : " ");
+        if (current == service_state_t::STARTED) {
+            cout << (was_skipped ? "s" : "+");
+        }
+        else {
+            cout << " ";
+        }
         cout << (target  == service_state_t::STARTED ? "}" : " ");
         
         if (current == service_state_t::STARTING) {
@@ -584,7 +590,17 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
         }
         
         cout << (target  == service_state_t::STOPPED ? "{" : " ");
-        cout << (current == service_state_t::STOPPED ? "-" : " ");
+        if (current == service_state_t::STOPPED) {
+            bool did_fail = false;
+            if (stop_reason == stopped_reason_t::TERMINATED) {
+                if (!WIFEXITED(exit_status) || WEXITSTATUS(exit_status) != 0) {
+                    did_fail = true;
+                }
+            }
+            else did_fail = (stop_reason != stopped_reason_t::NORMAL);
+
+            cout << (did_fail ? "X" : "-");
+        }
         cout << (target  == service_state_t::STOPPED ? "}" : " ");
 
         cout << "] " << name;
@@ -592,6 +608,15 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
         if (current != service_state_t::STOPPED && service_pid != -1) {
                cout << " (pid: " << service_pid << ")";
         }
+        
+        if (current == service_state_t::STOPPED && stop_reason == stopped_reason_t::TERMINATED) {
+            if (WIFEXITED(exit_status)) {
+                cout << " (exit status: " << WEXITSTATUS(exit_status) << ")";
+            }
+            else if (WIFSIGNALED(exit_status)) {
+                cout << " (signal: " << WSTOPSIG(exit_status) << ")";
+            }
+        }
 
         if (has_console) {
                cout << " (has console)";