From d27949f12fd7d12d31ac9b6b87d46a11894dca12 Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Wed, 2 Jan 2019 00:44:54 +0100 Subject: [PATCH] procd: guard fork_worker calls Usually respawn(), askfirst(), askconsole() and rcrespawn() are run only one time to start a worker child for the given inittab entry. In case we want to allow calling these functions several times, we need to ensure that we do not start multiple workers at the same time for the same inittab item. For this, we can re-use the remembered pid of the worker child, however, we need to reset this pid to allow a new instance in case the previous child exited. Signed-off-by: Michael Heimpold --- inittab.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/inittab.c b/inittab.c index 55554b9..3175048 100644 --- a/inittab.c +++ b/inittab.c @@ -120,14 +120,17 @@ static void child_exit(struct uloop_process *proc, int ret) { struct init_action *a = container_of(proc, struct init_action, proc); - DEBUG(4, "pid:%d\n", proc->pid); - uloop_timeout_set(&a->tout, a->respawn); + DEBUG(4, "pid:%d, exitcode:%d\n", proc->pid, ret); + proc->pid = 0; + + uloop_timeout_set(&a->tout, a->respawn); } static void respawn(struct uloop_timeout *tout) { struct init_action *a = container_of(tout, struct init_action, tout); - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void rcdone(struct runqueue *q) @@ -163,7 +166,8 @@ static void askfirst(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void askconsole(struct init_action *a) @@ -197,7 +201,8 @@ static void askconsole(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void rcrespawn(struct init_action *a) @@ -206,7 +211,8 @@ static void rcrespawn(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static struct init_handler handlers[] = { -- 2.25.1