1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 10:37:24 +00:00

SystemServer: Handle waitpid's status correctly

We used to call `did_exit()` directly with the status returned from
`waitpid` but the function expected an exit code. We now use several
of `wait`-related macros to deduce the correct information.
This commit is contained in:
Lucas CHOLLET 2023-05-06 00:41:01 -04:00 committed by Andreas Kling
parent 2c5a062c8f
commit 521ad55a61
2 changed files with 8 additions and 4 deletions

View File

@ -241,14 +241,17 @@ ErrorOr<void> Service::spawn(int socket_fd)
return {};
}
ErrorOr<void> Service::did_exit(int exit_code)
ErrorOr<void> Service::did_exit(int status)
{
using namespace AK::TimeLiterals;
VERIFY(m_pid > 0);
VERIFY(!m_multi_instance);
dbgln("Service {} has exited with exit code {}", name(), exit_code);
if (WIFEXITED(status))
dbgln("Service {} has exited with exit code {}", name(), WEXITSTATUS(status));
if (WIFSIGNALED(status))
dbgln("Service {} terminated due to signal {}", name(), WTERMSIG(status));
s_service_map.remove(m_pid);
m_pid = -1;
@ -257,7 +260,7 @@ ErrorOr<void> Service::did_exit(int exit_code)
return {};
auto run_time = m_run_timer.elapsed_time();
bool exited_successfully = exit_code == 0;
bool exited_successfully = WIFEXITED(status) == 0;
if (!exited_successfully && run_time < 1_sec) {
switch (m_restart_attempts) {

View File

@ -22,7 +22,8 @@ public:
bool is_enabled() const;
ErrorOr<void> activate();
ErrorOr<void> did_exit(int exit_code);
// Note: This is a `status` as in POSIX's wait syscall, not an exit-code.
ErrorOr<void> did_exit(int status);
static Service* find_by_pid(pid_t);