summaryrefslogtreecommitdiff
path: root/inittab.c
diff options
context:
space:
mode:
authorMichael Heimpold <mhei@heimpold.de>2019-01-02 00:44:54 +0100
committerJohn Crispin <john@phrozen.org>2019-10-27 14:20:12 +0100
commitd27949f12fd7d12d31ac9b6b87d46a11894dca12 (patch)
tree5e47dfabe316d989d7882c96da667018c741c003 /inittab.c
parent258aa04328a20213b12228d01d494c1e22f8d510 (diff)
downloadprocd-d27949f12fd7d12d31ac9b6b87d46a11894dca12.tar.gz
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 <mhei@heimpold.de>
Diffstat (limited to 'inittab.c')
-rw-r--r--inittab.c18
1 files 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[] = {