From 79bb09eac54d91bf76268baa50ecebea1ab19708 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 14 May 2020 16:20:27 +0200 Subject: Revert handling of wait type service to using state Signed-off-by: David Oberhollenzer --- initd/config.c | 23 +++++++++++++++++++++++ initd/init.h | 6 ++++++ initd/main.c | 32 ++++++++++---------------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/initd/config.c b/initd/config.c index d994faa..fa12ab2 100644 --- a/initd/config.c +++ b/initd/config.c @@ -15,6 +15,7 @@ static size_t queue_count[TGT_MAX]; /* current state */ static size_t queue_idx = 0; static int target = TGT_BOOT; +static svc_run_data_t *waiting = NULL; int config_load(void) { @@ -62,6 +63,24 @@ int config_load(void) return 0; } +void config_set_waiting(svc_run_data_t *rt) +{ + assert(waiting == NULL); + waiting = rt; +} + +bool config_is_waiting(void) +{ + if (waiting != NULL) { + if (waiting->state == STATE_RUNNING) + return true; + + waiting = NULL; + } + + return false; +} + svc_run_data_t *config_rt_data_by_pid(pid_t pid) { size_t i; @@ -79,6 +98,9 @@ svc_run_data_t *config_rt_data_by_pid(pid_t pid) svc_run_data_t *config_dequeue(void) { + if (config_is_waiting()) + return NULL; + if (queue_idx >= queue_count[target]) return NULL; @@ -100,6 +122,7 @@ void config_set_target(int tgt) target = tgt; queue_idx = 0; + waiting = NULL; } bool config_should_respawn(void) diff --git a/initd/init.h b/initd/init.h index 1a9f35a..61101c7 100644 --- a/initd/init.h +++ b/initd/init.h @@ -61,6 +61,12 @@ void config_set_target(int tgt); /* Ask whether we should respawn services in the current target */ bool config_should_respawn(void); +/* refuse to dequeue further services until this one terminates */ +void config_set_waiting(svc_run_data_t *rt); + +/* are we currently waiting for a service to terminate? */ +bool config_is_waiting(void); + /********** print_status.c **********/ void print_status(const svc_run_data_t *rt); diff --git a/initd/main.c b/initd/main.c index 6d46408..6485842 100644 --- a/initd/main.c +++ b/initd/main.c @@ -65,34 +65,22 @@ static void handle_exited(svc_run_data_t *rt) static void start_service(svc_run_data_t *rt) { - svc_run_data_t *terminated; + if (rt->svc->flags & SVC_FLAG_HAS_EXEC) { + rt->pid = runsvc(rt->svc); + if (rt->pid == -1) { + rt->state = STATE_FAILED; + } else { + rt->state = STATE_RUNNING; - if (!(rt->svc->flags & SVC_FLAG_HAS_EXEC)) { + if (rt->svc->type == SVC_WAIT) + config_set_waiting(rt); + } + } else { rt->status = EXIT_SUCCESS; rt->state = STATE_COMPLETED; - print_status(rt); - return; } - rt->pid = runsvc(rt->svc); - if (rt->pid == -1) { - rt->state = STATE_FAILED; - print_status(rt); - return; - } - - rt->state = STATE_RUNNING; print_status(rt); - - switch (rt->svc->type) { - case SVC_WAIT: - do { - terminated = wait_for_process(); - if (terminated != NULL) - handle_exited(terminated); - } while (terminated != rt); - break; - } } static void handle_signal(int signo) -- cgit v1.2.3