From 50369e9dc98b460fe37f1d8291f7812f2c74c1f6 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 22 Jun 2018 09:57:21 +0100 Subject: [PATCH] dinitctl: show if service was skipped or failed. Also update documentation accordingly. --- doc/manpages/dinitctl.8 | 8 +++++++- src/control.cc | 1 + src/dinitctl.cc | 31 ++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/doc/manpages/dinitctl.8 b/doc/manpages/dinitctl.8 index 05992b7..dc77cc4 100644 --- a/doc/manpages/dinitctl.8 +++ b/doc/manpages/dinitctl.8 @@ -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 diff --git a/src/control.cc b/src/control.cc index 7f84e2e..8373daa 100644 --- a/src/control.cc +++ b/src/control.cc @@ -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(sptr->get_stop_reason()); diff --git a/src/dinitctl.cc b/src/dinitctl.cc index 1bf06f7..17dc9d0 100644 --- a/src/dinitctl.cc +++ b/src/dinitctl.cc @@ -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(rbuffer[5]); + stopped_reason_t stop_reason = static_cast(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)"; -- 2.25.1