mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibCore+flock: Make Core::System::waitpid more ergonomic
This commit is contained in:
parent
315e1c705f
commit
0d328f3c86
Notes:
sideshowbarker
2024-07-17 21:11:59 +09:00
Author: https://github.com/juniorrantila Commit: https://github.com/SerenityOS/serenity/commit/0d328f3c86a Pull-request: https://github.com/SerenityOS/serenity/pull/11790 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/kleinesfilmroellchen ✅
@ -517,12 +517,13 @@ ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* c
|
||||
return child_pid;
|
||||
}
|
||||
|
||||
ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options)
|
||||
ErrorOr<WaitPidResult> waitpid(pid_t waitee, int options)
|
||||
{
|
||||
pid_t pid = ::waitpid(waitee, wstatus, options);
|
||||
int wstatus;
|
||||
pid_t pid = ::waitpid(waitee, &wstatus, options);
|
||||
if (pid < 0)
|
||||
return Error::from_syscall("waitpid"sv, -errno);
|
||||
return pid;
|
||||
return WaitPidResult { pid, wstatus };
|
||||
}
|
||||
|
||||
ErrorOr<void> setuid(uid_t uid)
|
||||
|
@ -85,7 +85,12 @@ ErrorOr<Optional<struct passwd>> getpwuid(uid_t);
|
||||
ErrorOr<Optional<struct group>> getgrgid(gid_t);
|
||||
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
|
||||
ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
|
||||
ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options);
|
||||
|
||||
struct WaitPidResult {
|
||||
pid_t pid;
|
||||
int status;
|
||||
};
|
||||
ErrorOr<WaitPidResult> waitpid(pid_t waitee, int options = 0);
|
||||
ErrorOr<void> setuid(uid_t);
|
||||
ErrorOr<void> seteuid(uid_t);
|
||||
ErrorOr<void> setgid(gid_t);
|
||||
|
@ -19,7 +19,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
}
|
||||
|
||||
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));
|
||||
auto [_, status] = TRY(Core::System::waitpid(child_pid));
|
||||
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user