blob: 0172d16f58aba2e45994abf8d1598fe3ffeff1a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Format.h>
#include <errno.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (argc < 3) {
warnln("usage: flock <path> <command...>");
return 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(child_pid, &status, 0) < 0) {
perror("waitpid");
return 1;
}
return WEXITSTATUS(status);
}
|