diff options
author | Nico Weber <thakis@chromium.org> | 2020-06-28 13:40:10 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-29 12:04:27 +0200 |
commit | 12cbc4ad0d57b7f403e0a27b491b098f1431a283 (patch) | |
tree | efe3ef1bb3555c24b3173bbfad4d97c503e3f585 /Libraries/LibC | |
parent | 301ac3c7e5d99f32ac9a70b51844ad7ce8c9d563 (diff) | |
download | serenity-12cbc4ad0d57b7f403e0a27b491b098f1431a283.zip |
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.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/stdlib.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index cc2d82da36..2571b4f257 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -36,6 +36,7 @@ #include <ctype.h> #include <errno.h> #include <signal.h> +#include <spawn.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -706,16 +707,10 @@ int system(const char* command) if (!command) return 1; - auto child = fork(); - if (child < 0) + pid_t child; + const char* argv[] = { "sh", "-c", command, nullptr }; + if ((errno = posix_spawn(&child, "/bin/sh", nullptr, nullptr, const_cast<char**>(argv), environ))) return -1; - - if (!child) { - int rc = execl("/bin/sh", "sh", "-c", command, nullptr); - ASSERT(rc < 0); - perror("execl"); - exit(127); - } int wstatus; waitpid(child, &wstatus, 0); return WEXITSTATUS(wstatus); |