aboutsummaryrefslogtreecommitdiff
path: root/initd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-13 19:24:06 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-14 01:26:14 +0200
commitf68692aa858a9b5ce17b0ab5f9ebe694f4ee12ab (patch)
treeeaa1ebd449eeada8559fc28b82bfed17daa030b4 /initd
parentdbe89195b258c1101b5dd37dfbf5f0d71c25e0fa (diff)
Partially restore old message printing behaviour
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd')
-rw-r--r--initd/main.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/initd/main.c b/initd/main.c
index c804105..d8319ea 100644
--- a/initd/main.c
+++ b/initd/main.c
@@ -1,17 +1,36 @@
/* SPDX-License-Identifier: ISC */
#include "init.h"
-static const char *status_str[] = {
- [STATE_OFF] = NULL,
- [STATE_QUEUED] = NULL,
- [STATE_RUNNING] ="\033[22;33m UP \033[0m",
- [STATE_COMPLETED] = "\033[22;32mDONE\033[0m",
- [STATE_FAILED] ="\033[22;31mFAIL\033[0m",
-};
-
-static void print_status(const char *msg, int type)
+static void print_status(svc_run_data_t *rt)
{
- printf("[%s] %s\n", status_str[type], msg);
+ 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);
}
@@ -32,7 +51,7 @@ static void respawn(svc_run_data_t *rt)
return;
fail:
rt->state = STATE_FAILED;
- print_status(rt->svc->desc, rt->state);
+ print_status(rt);
return;
}
@@ -61,7 +80,7 @@ static svc_run_data_t *wait_for_process(void)
rt->state = STATE_FAILED;
}
- print_status(rt->svc->desc, rt->state);
+ print_status(rt);
if (rt->svc->type == SVC_ONCE)
config_singleshot_terminated();
@@ -143,10 +162,10 @@ int main(void)
if (rt->pid == -1) {
rt->state = STATE_FAILED;
- print_status(svc->desc, rt->state);
+ print_status(rt);
} else {
rt->state = STATE_RUNNING;
- print_status(svc->desc, rt->state);
+ print_status(rt);
switch (svc->type) {
case SVC_WAIT:
@@ -164,7 +183,7 @@ int main(void)
} else {
rt->status = EXIT_SUCCESS;
rt->state = STATE_COMPLETED;
- print_status(svc->desc, rt->state);
+ print_status(rt);
}
check_target_completion();