1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

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.
This commit is contained in:
Nico Weber 2020-06-19 16:44:44 -04:00 committed by Andreas Kling
parent 5208856688
commit ed0740d73c

View file

@ -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[])