From 32c3ad35b4985718e2b92c979292f6b0f6816587 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 14 May 2020 01:15:58 +0200 Subject: Cleanup: split print_status back out again from initd/main.c Signed-off-by: David Oberhollenzer --- initd/Makemodule.am | 1 + initd/init.h | 4 ++++ initd/main.c | 33 --------------------------------- initd/print_status.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 initd/print_status.c diff --git a/initd/Makemodule.am b/initd/Makemodule.am index 6f6b523..afe802e 100644 --- a/initd/Makemodule.am +++ b/initd/Makemodule.am @@ -1,4 +1,5 @@ init_SOURCES = initd/main.c initd/init.h initd/runsvc.c initd/config.c +init_SOURCES += initd/print_status.c init_CPPFLAGS = $(AM_CPPFLAGS) init_CFLAGS = $(AM_CFLAGS) init_LDFLAGS = $(AM_LDFLAGS) diff --git a/initd/init.h b/initd/init.h index 813dedb..deb6da9 100644 --- a/initd/init.h +++ b/initd/init.h @@ -94,4 +94,8 @@ void config_singleshot_started(void); /* notify the configuration manager that a single shot service terminated */ void config_singleshot_terminated(void); +/********** print_status.c **********/ + +void print_status(const svc_run_data_t *rt); + #endif /* INIT_H */ diff --git a/initd/main.c b/initd/main.c index 26a04e2..9656daf 100644 --- a/initd/main.c +++ b/initd/main.c @@ -1,39 +1,6 @@ /* SPDX-License-Identifier: ISC */ #include "init.h" -static void print_status(svc_run_data_t *rt) -{ - const char *str; - char pre = '\n'; - - switch (rt->state) { - case STATE_RUNNING: - if (rt->svc->type == SVC_WAIT) { - str = "\033[22;33m .. \033[0m"; - } else { - str = "\033[22;32m UP \033[0m"; - } - break; - case STATE_COMPLETED: - if (rt->svc->type == SVC_WAIT) - pre = '\r'; - - str = "\033[22;32mDONE\033[0m"; - break; - case STATE_FAILED: - if (rt->svc->type == SVC_WAIT) - pre = '\r'; - - str = "\033[22;31mFAIL\033[0m"; - break; - default: - return; - } - - printf("%c[%s] %s", pre, str, rt->svc->desc); - fflush(stdout); -} - static void respawn(svc_run_data_t *rt) { if (rt->svc->rspwn_limit > 0) { diff --git a/initd/print_status.c b/initd/print_status.c new file mode 100644 index 0000000..9f0259a --- /dev/null +++ b/initd/print_status.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: ISC */ +#include "init.h" + +void print_status(const svc_run_data_t *rt) +{ + const char *str; + char pre = '\n'; + + switch (rt->state) { + case STATE_RUNNING: + if (rt->svc->type == SVC_WAIT) { + str = "\033[22;33m .. \033[0m"; + } else { + str = "\033[22;32m UP \033[0m"; + } + break; + case STATE_COMPLETED: + if (rt->svc->type == SVC_WAIT) + pre = '\r'; + + str = "\033[22;32mDONE\033[0m"; + break; + case STATE_FAILED: + if (rt->svc->type == SVC_WAIT) + pre = '\r'; + + str = "\033[22;31mFAIL\033[0m"; + break; + default: + return; + } + + printf("%c[%s] %s", pre, str, rt->svc->desc); + fflush(stdout); +} -- cgit v1.2.3