diff --git a/Libraries/LibCore/Process.cpp b/Libraries/LibCore/Process.cpp index 3dde4299c5d..4305a97cfac 100644 --- a/Libraries/LibCore/Process.cpp +++ b/Libraries/LibCore/Process.cpp @@ -335,19 +335,19 @@ ErrorOr Process::disown() } } -ErrorOr Process::wait_for_termination() +ErrorOr Process::wait_for_termination() { VERIFY(m_pid > 0); - bool exited_with_code_0 = true; + int exit_code = -1; int status; if (waitpid(m_pid, &status, 0) == -1) return Error::from_syscall("waitpid"sv, errno); if (WIFEXITED(status)) { - exited_with_code_0 &= WEXITSTATUS(status) == 0; + exit_code = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - exited_with_code_0 = false; + exit_code = 128 + WTERMSIG(status); } else if (WIFSTOPPED(status)) { // This is only possible if the child process is being traced by us. VERIFY_NOT_REACHED(); @@ -356,7 +356,7 @@ ErrorOr Process::wait_for_termination() } m_should_disown = false; - return exited_with_code_0; + return exit_code; } } diff --git a/Libraries/LibCore/Process.h b/Libraries/LibCore/Process.h index 9e99ff30270..24145022b23 100644 --- a/Libraries/LibCore/Process.h +++ b/Libraries/LibCore/Process.h @@ -79,8 +79,7 @@ public: ErrorOr disown(); #endif - // FIXME: Make it return an exit code. - ErrorOr wait_for_termination(); + ErrorOr wait_for_termination(); private: #ifndef AK_OS_WINDOWS diff --git a/Libraries/LibCore/ProcessWindows.cpp b/Libraries/LibCore/ProcessWindows.cpp index fc65784e8a6..61219a3eeef 100644 --- a/Libraries/LibCore/ProcessWindows.cpp +++ b/Libraries/LibCore/ProcessWindows.cpp @@ -146,7 +146,7 @@ pid_t Process::pid() const return GetProcessId(m_handle); } -ErrorOr Process::wait_for_termination() +ErrorOr Process::wait_for_termination() { auto result = WaitForSingleObject(m_handle, INFINITE); if (result == WAIT_FAILED) @@ -156,7 +156,7 @@ ErrorOr Process::wait_for_termination() if (!GetExitCodeProcess(m_handle, &exit_code)) return Error::from_windows_error(GetLastError()); - return !exit_code; + return exit_code; } }