From a772484f00eae0f8a4d5e73f23b36c50445c3c51 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 6 Jan 2025 17:18:43 +0100 Subject: [PATCH] lib/: Use _exit in case of execv errors Calling exit might trigger cleanup functions registered through atexit. Since some programs use this mechanism, be extra cautious to never release passwd/group locks too early. Reviewed-by: Alejandro Colomar Signed-off-by: Tobias Stoeckmann --- lib/run_part.c | 2 +- lib/spawn.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/run_part.c b/lib/run_part.c index 840d95119..890f837cd 100644 --- a/lib/run_part.c +++ b/lib/run_part.c @@ -32,7 +32,7 @@ static int run_part(char *script_path, const char *name, const char *action) setenv("SUBJECT",name,1); execv(script_path,args); fprintf(shadow_logfd, "execv: %s\n", strerror(errno)); - exit(1); + _exit(1); } pid_status = wait(&wait_status); diff --git a/lib/spawn.c b/lib/spawn.c index 57a412199..0a2b10950 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -35,11 +35,11 @@ run_command(const char *cmd, const char *argv[], (void) execve (cmd, (char * const *) argv, (char * const *) envp); if (ENOENT == errno) { - exit (E_CMD_NOTFOUND); + _exit (E_CMD_NOTFOUND); } fprintf (shadow_logfd, "%s: cannot execute %s: %s\n", shadow_progname, cmd, strerror (errno)); - exit (E_CMD_NOEXEC); + _exit (E_CMD_NOEXEC); } else if ((pid_t)-1 == pid) { fprintf (shadow_logfd, "%s: cannot execute %s: %s\n", shadow_progname, cmd, strerror (errno)); -- 2.47.2