aboutsummaryrefslogtreecommitdiff
path: root/initd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-09 01:11:59 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-09 01:11:59 +0200
commit1616a62a57c427b1d50ffa5a08bf8899508ee0ea (patch)
tree0a4d2d574e396ebc7757d703690cef0cb043b899 /initd
parent8dfbca8e4145118fd5451931e094a1964d06b2db (diff)
Minor simplifications/cleanups
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd')
-rw-r--r--initd/init.h4
-rw-r--r--initd/main.c16
-rw-r--r--initd/supervisor.c58
3 files changed, 32 insertions, 46 deletions
diff --git a/initd/init.h b/initd/init.h
index 6e5ad8f..005fbba 100644
--- a/initd/init.h
+++ b/initd/init.h
@@ -44,10 +44,6 @@ typedef struct {
pid_t pid; /* if still running, the pid */
} svc_run_data_t;
-/********** main.c **********/
-
-void target_completed(int target);
-
/********** runsvc.c **********/
/*
diff --git a/initd/main.c b/initd/main.c
index caa2a1e..5ad265d 100644
--- a/initd/main.c
+++ b/initd/main.c
@@ -28,22 +28,6 @@ static void handle_signal(int signo)
}
}
-void target_completed(int target)
-{
- switch (target) {
- case TGT_BOOT:
- break;
- case TGT_SHUTDOWN:
- for (;;)
- reboot(RB_POWER_OFF);
- break;
- case TGT_REBOOT:
- for (;;)
- reboot(RB_AUTOBOOT);
- break;
- }
-}
-
int main(void)
{
struct sigaction act;
diff --git a/initd/supervisor.c b/initd/supervisor.c
index 1e7e844..3372e7f 100644
--- a/initd/supervisor.c
+++ b/initd/supervisor.c
@@ -13,9 +13,8 @@ static size_t queue_start[TGT_MAX];
static size_t queue_count[TGT_MAX];
/* current state */
-static size_t queue_idx;
-
-static int target = -1;
+static size_t queue_idx = 0;
+static int target = TGT_BOOT;
static size_t singleshot = 0;
static bool waiting = false;
@@ -35,18 +34,6 @@ static void print_status(const char *msg, int type)
fflush(stdout);
}
-static svc_run_data_t *run_time_data_from_pid(pid_t pid)
-{
- size_t i;
-
- for (i = 0; i < rt_count; ++i) {
- if (rt_data[i].pid == pid)
- return rt_data + i;
- }
-
- return NULL;
-}
-
static void respawn(svc_run_data_t *rt)
{
if (rt->svc->rspwn_limit > 0) {
@@ -68,14 +55,40 @@ fail:
return;
}
+static void check_target_completion(void)
+{
+ if (singleshot > 0 || queue_idx < queue_count[target] || waiting)
+ return;
+
+ switch (target) {
+ case TGT_BOOT:
+ break;
+ case TGT_SHUTDOWN:
+ for (;;)
+ reboot(RB_POWER_OFF);
+ break;
+ case TGT_REBOOT:
+ for (;;)
+ reboot(RB_AUTOBOOT);
+ break;
+ }
+}
+
void supervisor_handle_exited(pid_t pid, int status)
{
- svc_run_data_t *rt = run_time_data_from_pid(pid);
+ svc_run_data_t *rt;
service_t *svc;
+ size_t i;
- if (rt == NULL)
+ for (i = 0; i < rt_count; ++i) {
+ if (rt_data[i].pid == pid)
+ break;
+ }
+
+ if (i >= rt_count)
return;
+ rt = rt_data + i;
svc = rt->svc;
rt->status = status;
rt->pid = -1;
@@ -96,8 +109,7 @@ void supervisor_handle_exited(pid_t pid, int status)
if (svc->type == SVC_ONCE)
singleshot -= 1;
- if (singleshot == 0 && queue_idx >= queue_count[target] && !waiting)
- target_completed(target);
+ check_target_completion();
}
}
@@ -155,10 +167,6 @@ void supervisor_init(void)
}
/* initialize state */
- singleshot = 0;
- queue_idx = 0;
- waiting = false;
- target = TGT_BOOT;
status = STATE_COMPLETED;
for (i = 0; i < queue_count[target]; ++i)
@@ -212,9 +220,7 @@ bool supervisor_process_queues(void)
}
print_status(svc->desc, rt->state);
-
- if (singleshot == 0 && !waiting && queue_idx >= count)
- target_completed(target);
+ check_target_completion();
out_unblock:
sigprocmask(SIG_SETMASK, &old_mask, NULL);
return ret;