From 0b3f9dd528c8446356dd277f16137bffe01315bd Mon Sep 17 00:00:00 2001 From: angelcaru Date: Fri, 20 Nov 2026 17:58:39 +0100 Subject: [PATCH] Use _exit instead of exit in cmd__start_process This prevents exit handlers from being run when execvp fails. --- nob.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nob.h b/nob.h index 8c01658..e8bb2fa 100644 --- a/nob.h +++ b/nob.h @@ -1593,24 +1593,25 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout, } if (cpid == 0) { + // We use _exit instead of exit in case of error here to avoid running exit handlers (atexit) when execvp fails. if (fdin) { if (dup2(*fdin, STDIN_FILENO) < 0) { nob_log(NOB_ERROR, "Could not setup stdin for child process: %s", strerror(errno)); - exit(1); + _exit(1); } } if (fdout) { if (dup2(*fdout, STDOUT_FILENO) < 0) { nob_log(NOB_ERROR, "Could not setup stdout for child process: %s", strerror(errno)); - exit(1); + _exit(1); } } if (fderr) { if (dup2(*fderr, STDERR_FILENO) < 0) { nob_log(NOB_ERROR, "Could not setup stderr for child process: %s", strerror(errno)); - exit(1); + _exit(1); } } @@ -1622,7 +1623,7 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout, if (execvp(cmd.items[0], (char * const*) cmd_null.items) < 0) { nob_log(NOB_ERROR, "Could not exec child process for %s: %s", cmd.items[0], strerror(errno)); - exit(1); + _exit(1); } NOB_UNREACHABLE("nob_cmd_run_async_redirect"); }