From c85e28b971d527c115ae3e11e9564fb5d40df90c Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 9 Apr 2021 18:59:33 +0200 Subject: [PATCH] Yield execution in forked children back to PID 1 - Speeds up start-up a bit - Ensures the child is moved to its cgroup as soon as possible Signed-off-by: Joachim Wiberg --- src/exec.c | 4 ++++ src/helpers.h | 1 + src/service.c | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/exec.c b/src/exec.c index c2eee0f4..45f1e3fc 100644 --- a/src/exec.c +++ b/src/exec.c @@ -389,6 +389,8 @@ pid_t run_getty(char *tty, char *baud, char *term, int noclear, int nowait, stru speed_t speed; int rc = 1; + sched_yield(); + speed = stty_parse_speed(baud); prepare_tty(tty, speed, "tty", rlimit); if (activate_console(noclear, nowait)) { @@ -412,6 +414,8 @@ pid_t run_getty2(char *tty, char *cmd, char *args[], int noclear, int nowait, st if (!pid) { int rc = 1; + sched_yield(); + /* Dunno speed, tell stty() to not mess with it */ prepare_tty(tty, B0, "getty", rlimit); if (activate_console(noclear, nowait)) { diff --git a/src/helpers.h b/src/helpers.h index 03fac197..54fdd55a 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -26,6 +26,7 @@ #define FINIT_HELPERS_H_ #include +#include /* sched_yield() */ #include #include #include diff --git a/src/service.c b/src/service.c index 4f0320ac..58acd141 100644 --- a/src/service.c +++ b/src/service.c @@ -25,7 +25,6 @@ #include "config.h" /* Generated by configure script */ #include /* isblank() */ -#include /* sched_yield() */ #include #include #include @@ -196,6 +195,8 @@ static int lredirect(svc_t *svc) char *tag = basename(svc->cmd); char *prio = "daemon.info"; + sched_yield(); + fds = open(ptsname(fd), O_RDONLY); close(fd); if (fds == -1) @@ -445,6 +446,8 @@ static int service_start(svc_t *svc) #endif char *args[MAX_NUM_SVC_ARGS + 1]; + sched_yield(); + /* Set configured limits */ for (int i = 0; i < RLIMIT_NLIMITS; i++) { if (setrlimit(i, &svc->rlimit[i]) == -1)