From 3d50a28fe3aae3c48d76165ca707d6c8567de4d7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 28 Feb 2021 21:25:54 +0100 Subject: [PATCH] Make sure to _exit() TTY child also on error Signed-off-by: Joachim Wiberg --- src/exec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/exec.c b/src/exec.c index 14558500..bccb4370 100644 --- a/src/exec.c +++ b/src/exec.c @@ -386,12 +386,15 @@ pid_t run_getty(char *tty, char *baud, char *term, int noclear, int nowait, stru pid = fork(); if (!pid) { speed_t speed; + int rc = 1; speed = stty_parse_speed(baud); logit(LOG_INFO, "Starting built-in getty on %s, speed %u", tty, speed); prepare_tty(tty, speed, "tty", rlimit); if (activate_console(noclear, nowait)) - _exit(getty(tty, speed, term, NULL)); + rc = getty(tty, speed, term, NULL); + + _exit(rc); } return pid; @@ -403,14 +406,16 @@ pid_t run_getty2(char *tty, char *cmd, char *args[], int noclear, int nowait, st pid = fork(); if (!pid) { + int rc = 1; + /* Dunno speed, tell stty() to not mess with it */ logit(LOG_INFO, "Starting external getty on %s, speed %u", tty, B0); prepare_tty(tty, B0, "getty", rlimit); if (activate_console(noclear, nowait)) - _exit(execv(cmd, args)); + rc = execv(cmd, args); vhangup(); - exit(0); + _exit(rc); } return pid; @@ -422,9 +427,13 @@ pid_t run_sh(char *tty, int noclear, int nowait, struct rlimit rlimit[]) pid = fork(); if (!pid) { + int rc = 1; + prepare_tty(tty, B0, "finit-sh", rlimit); if (activate_console(noclear, nowait)) - _exit(sh(tty)); + rc = sh(tty); + + _exit(rc); } return pid;