diff --git a/native/WinRestarter/restarter.c b/native/WinRestarter/restarter.c index d6f9c4aca8b2..d1253ab6dc7c 100644 --- a/native/WinRestarter/restarter.c +++ b/native/WinRestarter/restarter.c @@ -21,11 +21,13 @@ #define PROVIDER_NAME L"JB-Restarter" -#define ERR_OPEN_PROCESS (0xE0000000 + 101) -#define ERR_COMMAND_TOO_LONG (0xE0000000 + 102) -#define ERR_CREATE_PROCESS (0xE0000000 + 103) -#define ERR_GET_EXIT_CODE (0xE0000000 + 104) -#define WARN_COMMAND_FAILED (0x80000000 + 201) +#define ERR_OPEN_PROCESS (0xE0000000 + 100) +#define ERR_MAIN_WAIT_FAILED (0xE0000000 + 101) +#define ERR_COMMAND_TOO_LONG (0xE0000000 + 110) +#define ERR_CREATE_PROCESS (0xE0000000 + 111) +#define ERR_COMMAND_WAIT_FAILED (0xE0000000 + 112) +#define ERR_GET_EXIT_CODE (0xE0000000 + 113) +#define WARN_COMMAND_FAILED (0x80000000 + 200) #define COMMAND_SIZE 32768 #define MESSAGE_SIZE (COMMAND_SIZE + 1024) @@ -67,12 +69,18 @@ int wmain(int argc, wchar_t *argv[]) { static void wait_for_parent(const wchar_t *pid_arg) { int pid = (int)wcstol(pid_arg, NULL, 10); + HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, pid); if (parent == NULL) { log_event(ERR_OPEN_PROCESS, "OpenProcess(%d): %d", pid, (int)GetLastError()); return; } - WaitForSingleObject(parent, INFINITE); + + DWORD res = WaitForSingleObject(parent, INFINITE); + if (res != WAIT_OBJECT_0) { + log_event(ERR_MAIN_WAIT_FAILED, "WaitForSingleObject: %08X/%d", (unsigned int)res, (int)GetLastError()); + } + CloseHandle(parent); } @@ -103,7 +111,10 @@ static void run_command(int cmd_argc, wchar_t *cmd_argv[], BOOL last) { } if (!last) { - WaitForSingleObject(pi.hProcess, INFINITE); + DWORD res = WaitForSingleObject(pi.hProcess, INFINITE); + if (res != WAIT_OBJECT_0) { + log_event(ERR_COMMAND_WAIT_FAILED, "WaitForSingleObject: %08X/%d", (unsigned int)res, (int)GetLastError()); + } DWORD ec; if (!GetExitCodeProcess(pi.hProcess, &ec)) {