mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 18:46:18 +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:
parent
2c5a062c8f
commit
521ad55a61
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue