2020-04-06 12:09:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 12:09:01 +03:00
|
|
|
*/
|
|
|
|
|
2021-05-31 17:43:25 +03:00
|
|
|
#include <AK/Format.h>
|
2021-05-14 17:32:57 +03:00
|
|
|
#include <errno.h>
|
2020-06-28 20:40:10 +03:00
|
|
|
#include <spawn.h>
|
2020-01-20 22:44:29 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc < 3) {
|
2021-05-31 17:43:25 +03:00
|
|
|
warnln("usage: flock <path> <command...>");
|
2021-06-01 21:27:59 +03:00
|
|
|
return 1;
|
2020-01-20 22:44:29 +03:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:40:10 +03:00
|
|
|
pid_t child_pid;
|
|
|
|
if ((errno = posix_spawnp(&child_pid, argv[2], nullptr, nullptr, &argv[2], environ))) {
|
|
|
|
perror("posix_spawn");
|
|
|
|
return 1;
|
2020-01-20 22:44:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int status;
|
2020-06-28 20:40:10 +03:00
|
|
|
if (waitpid(child_pid, &status, 0) < 0) {
|
2020-01-20 22:44:29 +03:00
|
|
|
perror("waitpid");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return WEXITSTATUS(status);
|
|
|
|
}
|