mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:28:13 +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:
parent
301ac3c7e5
commit
12cbc4ad0d
11 changed files with 65 additions and 101 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -121,20 +122,12 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (access(home_directory.characters(), F_OK) != -1) {
|
||||
auto child = fork();
|
||||
|
||||
if (child < 0) {
|
||||
perror("fork");
|
||||
pid_t child;
|
||||
const char* argv[] = { "rm", "-r", home_directory.characters(), nullptr };
|
||||
if ((errno = posix_spawn(&child, "/bin/rm", nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
||||
perror("posix_spawn");
|
||||
return 12;
|
||||
}
|
||||
|
||||
if (!child) {
|
||||
int rc = execl("/bin/rm", "rm", "-r", home_directory.characters(), nullptr);
|
||||
ASSERT(rc < 0);
|
||||
perror("execl");
|
||||
exit(127);
|
||||
}
|
||||
|
||||
int wstatus;
|
||||
if (waitpid(child, &wstatus, 0) < 0) {
|
||||
perror("waitpid");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue