flock: Port to LibMain

This commit is contained in:
Kenneth Myhra 2021-12-13 18:45:02 +01:00 committed by Brian Gianforcaro
parent 11578c623c
commit 160f3224a5
Notes: sideshowbarker 2024-07-17 22:43:48 +09:00
2 changed files with 7 additions and 15 deletions

View file

@ -90,6 +90,7 @@ target_link_libraries(expr LibRegex)
target_link_libraries(fdtdump LibDeviceTree LibMain) target_link_libraries(fdtdump LibDeviceTree LibMain)
target_link_libraries(file LibGfx LibIPC LibCompress LibMain) target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
target_link_libraries(find LibMain) target_link_libraries(find LibMain)
target_link_libraries(flock LibMain)
target_link_libraries(fortune LibMain) target_link_libraries(fortune LibMain)
target_link_libraries(functrace LibDebug LibX86) target_link_libraries(functrace LibDebug LibX86)
target_link_libraries(gml-format LibGUI) target_link_libraries(gml-format LibGUI)

View file

@ -5,30 +5,21 @@
*/ */
#include <AK/Format.h> #include <AK/Format.h>
#include <errno.h> #include <LibCore/System.h>
#include <spawn.h> #include <LibMain/Main.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
if (argc < 3) { if (arguments.strings.size() < 3) {
warnln("usage: flock <path> <command...>"); warnln("usage: flock <path> <command...>");
return 1; return 1;
} }
pid_t child_pid; pid_t child_pid = TRY(Core::System::posix_spawnp(arguments.strings[2], nullptr, nullptr, &arguments.argv[2], environ));
if ((errno = posix_spawnp(&child_pid, argv[2], nullptr, nullptr, &argv[2], environ))) { int status = TRY(Core::System::waitpid(child_pid, &status, 0));
perror("posix_spawn");
return 1;
}
int status;
if (waitpid(child_pid, &status, 0) < 0) {
perror("waitpid");
return 1;
}
return WEXITSTATUS(status); return WEXITSTATUS(status);
} }