1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

Everywhere: Replace some uses of fork/exec with posix_spawn

It's less code, and it's potentially more efficient once
posix_spawn is a real syscall.
This commit is contained in:
Nico Weber 2020-06-28 13:40:10 -04:00 committed by Andreas Kling
parent 301ac3c7e5
commit 12cbc4ad0d
11 changed files with 65 additions and 101 deletions

View file

@ -40,6 +40,7 @@
#include <LibGUI/MessageBox.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibKeyboard/CharacterMap.h>
#include <spawn.h>
int main(int argc, char** argv)
{
@ -123,18 +124,12 @@ int main(int argc, char** argv)
GUI::MessageBox::show("Please select character mapping file.", "Keyboard settings", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window);
return;
}
pid_t child_pid = fork();
if (child_pid < 0) {
perror("fork");
pid_t child_pid;
const char* argv[] = { "/bin/keymap", character_map_file.characters(), nullptr };
if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
exit(1);
}
if (child_pid == 0) {
if (execl("/bin/keymap", "/bin/keymap", character_map_file.characters(), nullptr) < 0) {
perror("execl");
exit(1);
}
}
if (quit)
app.quit();
};