summaryrefslogtreecommitdiff
path: root/Userland/flock.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-06-28 13:40:10 -0400
committerAndreas Kling <kling@serenityos.org>2020-06-29 12:04:27 +0200
commit12cbc4ad0d57b7f403e0a27b491b098f1431a283 (patch)
treeefe3ef1bb3555c24b3173bbfad4d97c503e3f585 /Userland/flock.cpp
parent301ac3c7e5d99f32ac9a70b51844ad7ce8c9d563 (diff)
downloadserenity-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 'Userland/flock.cpp')
-rw-r--r--Userland/flock.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/flock.cpp b/Userland/flock.cpp
index 685d58d952..dade8a2c44 100644
--- a/Userland/flock.cpp
+++ b/Userland/flock.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
@@ -36,15 +37,14 @@ int main(int argc, char** argv)
return 0;
}
- if (!fork()) {
- if (execvp(argv[2], &argv[2]) < 0) {
- perror("execvp");
- exit(1);
- }
+ pid_t child_pid;
+ if ((errno = posix_spawnp(&child_pid, argv[2], nullptr, nullptr, &argv[2], environ))) {
+ perror("posix_spawn");
+ return 1;
}
int status;
- if (waitpid(-1, &status, 0) < 0) {
+ if (waitpid(child_pid, &status, 0) < 0) {
perror("waitpid");
return 1;
}