2020-04-06 09:09:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 09:09:01 +00:00
|
|
|
*/
|
|
|
|
|
2021-05-31 14:43:25 +00:00
|
|
|
#include <AK/Format.h>
|
2021-12-13 17:45:02 +00:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2020-01-20 19:44:29 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-12-13 17:45:02 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-01-20 19:44:29 +00:00
|
|
|
{
|
2021-12-13 17:45:02 +00:00
|
|
|
if (arguments.strings.size() < 3) {
|
2021-05-31 14:43:25 +00:00
|
|
|
warnln("usage: flock <path> <command...>");
|
2021-06-01 18:27:59 +00:00
|
|
|
return 1;
|
2020-01-20 19:44:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:45:02 +00:00
|
|
|
pid_t child_pid = TRY(Core::System::posix_spawnp(arguments.strings[2], nullptr, nullptr, &arguments.argv[2], environ));
|
2022-01-10 13:34:09 +00:00
|
|
|
auto [_, status] = TRY(Core::System::waitpid(child_pid));
|
2020-01-20 19:44:29 +00:00
|
|
|
|
|
|
|
return WEXITSTATUS(status);
|
|
|
|
}
|