aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-08 15:39:36 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-08 15:43:56 +0200
commit8dfbca8e4145118fd5451931e094a1964d06b2db (patch)
tree64374f851b820e1b6adb2d7f80f4914e1bc54f71
parent9430785779a178c2226b86e9ac46013123dea76a (diff)
Simplify status printing
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
-rw-r--r--initd/supervisor.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/initd/supervisor.c b/initd/supervisor.c
index 6fdaae1..1e7e844 100644
--- a/initd/supervisor.c
+++ b/initd/supervisor.c
@@ -21,29 +21,17 @@ static bool waiting = false;
/*****************************************************************************/
-enum {
- STATUS_OK = 0,
- STATUS_FAIL,
- STATUS_WAIT,
- STATUS_STARTED,
-};
-
static const char *status_str[] = {
- [STATUS_OK] = "\033[22;32m OK \033[0m",
- [STATUS_FAIL] ="\033[22;31mFAIL\033[0m",
- [STATUS_WAIT] = "\033[22;33m .. \033[0m",
- [STATUS_STARTED] ="\033[22;32m UP \033[0m",
+ [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, bool update)
+static void print_status(const char *msg, int type)
{
- if (update)
- fputc('\r', stdout);
-
- printf("[%s] %s", status_str[type], msg);
-
- if (type != STATUS_WAIT)
- fputc('\n', stdout);
+ printf("[%s] %s\n", status_str[type], msg);
fflush(stdout);
}
@@ -75,8 +63,8 @@ static void respawn(svc_run_data_t *rt)
rt->state = STATE_RUNNING;
return;
fail:
- print_status(rt->svc->desc, STATUS_FAIL, false);
rt->state = STATE_FAILED;
+ print_status(rt->svc->desc, rt->state);
return;
}
@@ -98,14 +86,12 @@ void supervisor_handle_exited(pid_t pid, int status)
} else {
if (rt->status == EXIT_SUCCESS) {
rt->state = STATE_COMPLETED;
- print_status(svc->desc, STATUS_OK,
- svc->type == SVC_WAIT);
} else {
rt->state = STATE_FAILED;
- print_status(svc->desc, STATUS_FAIL,
- svc->type == SVC_WAIT);
}
+ print_status(svc->desc, rt->state);
+
waiting = false;
if (svc->type == SVC_ONCE)
singleshot -= 1;
@@ -131,7 +117,7 @@ void supervisor_set_target(int next)
void supervisor_init(void)
{
- int status = STATUS_FAIL;
+ int status = STATE_FAILED;
service_t *it;
size_t i, j;
@@ -148,7 +134,6 @@ void supervisor_init(void)
rt_data = calloc(rt_count, sizeof(rt_data[0]));
if (rt_data == NULL) {
- status = STATUS_FAIL;
rt_count = 0;
goto out;
}
@@ -174,12 +159,12 @@ void supervisor_init(void)
queue_idx = 0;
waiting = false;
target = TGT_BOOT;
- status = STATUS_OK;
+ status = STATE_COMPLETED;
for (i = 0; i < queue_count[target]; ++i)
rt_data[queue_start[target] + i].state = STATE_QUEUED;
out:
- print_status("reading configuration from " SVCDIR, status, false);
+ print_status("reading configuration from " SVCDIR, status);
}
bool supervisor_process_queues(void)
@@ -209,29 +194,25 @@ bool supervisor_process_queues(void)
if (rt->pid == -1) {
rt->state = STATE_FAILED;
- print_status(rt->svc->desc, STATUS_FAIL, false);
} else {
rt->state = STATE_RUNNING;
switch (svc->type) {
case SVC_WAIT:
- print_status(svc->desc, STATUS_WAIT, false);
waiting = true;
break;
- case SVC_RESPAWN:
- print_status(svc->desc, STATUS_STARTED, false);
- break;
case SVC_ONCE:
singleshot += 1;
break;
}
}
} else {
- print_status(svc->desc, STATUS_OK, false);
rt->status = EXIT_SUCCESS;
rt->state = STATE_COMPLETED;
}
+ print_status(svc->desc, rt->state);
+
if (singleshot == 0 && !waiting && queue_idx >= count)
target_completed(target);
out_unblock: