mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
flock: Port to LibMain
This commit is contained in:
parent
11578c623c
commit
160f3224a5
2 changed files with 7 additions and 15 deletions
|
@ -90,6 +90,7 @@ target_link_libraries(expr LibRegex)
|
|||
target_link_libraries(fdtdump LibDeviceTree LibMain)
|
||||
target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
|
||||
target_link_libraries(find LibMain)
|
||||
target_link_libraries(flock LibMain)
|
||||
target_link_libraries(fortune LibMain)
|
||||
target_link_libraries(functrace LibDebug LibX86)
|
||||
target_link_libraries(gml-format LibGUI)
|
||||
|
|
|
@ -5,30 +5,21 @@
|
|||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <errno.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.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...>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid_t child_pid;
|
||||
if ((errno = posix_spawnp(&child_pid, argv[2], nullptr, nullptr, &argv[2], environ))) {
|
||||
perror("posix_spawn");
|
||||
return 1;
|
||||
}
|
||||
pid_t child_pid = TRY(Core::System::posix_spawnp(arguments.strings[2], nullptr, nullptr, &arguments.argv[2], environ));
|
||||
int status = TRY(Core::System::waitpid(child_pid, &status, 0));
|
||||
|
||||
int status;
|
||||
if (waitpid(child_pid, &status, 0) < 0) {
|
||||
perror("waitpid");
|
||||
return 1;
|
||||
}
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue