ladybird/Userland/Utilities/flock.cpp

25 lines
626 B
C++
Raw Normal View History

2020-04-06 09:09:01 +00:00
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
2020-04-06 09:09:01 +00:00
*/
#include <AK/Format.h>
2021-12-13 17:45:02 +00:00
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <sys/wait.h>
#include <unistd.h>
2021-12-13 17:45:02 +00:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
2021-12-13 17:45:02 +00:00
if (arguments.strings.size() < 3) {
warnln("usage: flock <path> <command...>");
return 1;
}
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));
auto [_, status] = TRY(Core::System::waitpid(child_pid));
return WEXITSTATUS(status);
}