Skip to content

Commit 9ff75f4

Browse files
committed
LibWebView: Check the actual Ladybird process exit code on Windows
Even if the process has died, OpenProcess returns a non-null handle (unless some error occurred). We need to check the exit code.
1 parent 6f0d7f1 commit 9ff75f4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Libraries/LibWebView/Process.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,26 @@ ErrorOr<Optional<pid_t>> Process::get_process_pid(StringView process_name, Strin
8181
TRY(Core::System::unlink(pid_path));
8282
return OptionalNone {};
8383
}
84+
8485
bool const process_not_found = [&pid]() {
8586
#if defined(AK_OS_WINDOWS)
8687
HANDLE process_handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, *pid);
88+
if (process_handle == nullptr)
89+
return true;
90+
91+
// FIXME: We should create an RAII wrapper around HANDLE objects.
8792
ScopeGuard handle_guard = [&process_handle] { CloseHandle(process_handle); };
88-
return process_handle == nullptr;
93+
DWORD exit_code = 0;
94+
95+
if (GetExitCodeProcess(process_handle, &exit_code) == 0)
96+
return true;
97+
98+
return exit_code != STILL_ACTIVE;
8999
#else
90100
return kill(*pid, 0) < 0;
91101
#endif
92102
}();
103+
93104
if (process_not_found) {
94105
warnln("{} PID file '{}' exists with PID {}, but process cannot be found", process_name, pid_path, *pid);
95106
TRY(Core::System::unlink(pid_path));

0 commit comments

Comments
 (0)