1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +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

@ -29,6 +29,7 @@
#include <AK/LexicalPath.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/DirIterator.h>
#include <spawn.h>
#include <stdio.h>
#include <sys/stat.h>
@ -125,18 +126,12 @@ bool Launcher::open_with_handler_name(const URL& url, const String& handler_name
bool spawn(String executable, String argument)
{
pid_t child_pid = fork();
if (child_pid < 0) {
perror("fork");
pid_t child_pid;
const char* argv[] = { executable.characters(), argument.characters(), nullptr };
if ((errno = posix_spawn(&child_pid, executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
return false;
}
if (child_pid == 0) {
if (execl(executable.characters(), executable.characters(), argument.characters(), nullptr) < 0) {
perror("execl");
return false;
}
ASSERT_NOT_REACHED();
}
return true;
}