mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:47:36 +00:00
LibCore+flock: Make Core::System::waitpid more ergonomic
This commit is contained in:
parent
315e1c705f
commit
0d328f3c86
3 changed files with 11 additions and 5 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue