From ed0740d73c40dfdf6f1422629f37a0e9930d80c1 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 19 Jun 2020 16:44:44 -0400 Subject: [PATCH] LibC: In posix_spawn(), use _exit instead of exit on child error posix_spawn() tries to present semantics as if no fork() is happening behind the scenes, so running arbitrary atexit handlers of the parent in the child seems like the wrong thing to do. --- Libraries/LibC/spawn.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Libraries/LibC/spawn.cpp b/Libraries/LibC/spawn.cpp index 4c13ccd1e2..c68967fe70 100644 --- a/Libraries/LibC/spawn.cpp +++ b/Libraries/LibC/spawn.cpp @@ -56,23 +56,23 @@ extern "C" { if (flags & POSIX_SPAWN_RESETIDS) { if (seteuid(getuid()) < 0) { perror("posix_spawn seteuid"); - exit(127); + _exit(127); } if (setegid(getgid()) < 0) { perror("posix_spawn setegid"); - exit(127); + _exit(127); } } if (flags & POSIX_SPAWN_SETPGROUP) { if (setpgid(0, attr->pgroup) < 0) { perror("posix_spawn setpgid"); - exit(127); + _exit(127); } } if (flags & POSIX_SPAWN_SETSCHEDPARAM) { if (sched_setparam(0, &attr->schedparam) < 0) { perror("posix_spawn sched_setparam"); - exit(127); + _exit(127); } } if (flags & POSIX_SPAWN_SETSIGDEF) { @@ -85,20 +85,20 @@ extern "C" { for (int i = 0; i < NSIG; ++i) { if (sigismember(&sigdefault, i) && sigaction(i, &default_action, nullptr) < 0) { perror("posix_spawn sigaction"); - exit(127); + _exit(127); } } } if (flags & POSIX_SPAWN_SETSIGMASK) { if (sigprocmask(SIG_SETMASK, &attr->sigmask, nullptr) < 0) { perror("posix_spawn sigprocmask"); - exit(127); + _exit(127); } } if (flags & POSIX_SPAWN_SETSID) { if (setsid() < 0) { perror("posix_spawn setsid"); - exit(127); + _exit(127); } } @@ -109,14 +109,14 @@ extern "C" { for (const auto& action : file_actions->state->actions) { if (action() < 0) { perror("posix_spawn file action"); - exit(127); + _exit(127); } } } exec(path, argv, envp); perror("posix_spawn exec"); - exit(127); + _exit(127); } int posix_spawn(pid_t* out_pid, const char* path, const posix_spawn_file_actions_t* file_actions, const posix_spawnattr_t* attr, char* const argv[], char* const envp[])