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-12-13 20:45:02 +03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2020-01-20 22:44:29 +03:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-12-13 20:45:02 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-01-20 22:44:29 +03:00
|
|
|
{
|
2021-12-13 20:45:02 +03:00
|
|
|
if (arguments.strings.size() < 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
|
|
|
}
|
|
|
|
|
2021-12-13 20:45:02 +03:00
|
|
|
pid_t child_pid = TRY(Core::System::posix_spawnp(arguments.strings[2], nullptr, nullptr, &arguments.argv[2], environ));
|
2022-01-10 16:34:09 +03:00
|
|
|
auto [_, status] = TRY(Core::System::waitpid(child_pid));
|
2020-01-20 22:44:29 +03:00
|
|
|
|
|
|
|
return WEXITSTATUS(status);
|
|
|
|
}
|