From d3b6102228e907df8f3499097a1afc06f4867a25 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 10 Dec 2016 12:36:04 +0100 Subject: [PATCH] Changed: Check return code of WaitForSingleObject and log error --- code/nel/src/misc/common.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 1ae3f44fb..ee9e84512 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -1012,20 +1012,32 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st if (!createProcess(programName, arguments, log, pi)) return -1; // Successfully created the process. Wait for it to finish. - WaitForSingleObject(pi.hProcess, INFINITE); + DWORD ret = WaitForSingleObject(pi.hProcess, INFINITE); - // Get the exit code. - DWORD exitCode = 0; - BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode); + if (ret == WAIT_OBJECT_0) + { + // Get the exit code. + DWORD exitCode = 0; + BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode); - //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); - if (ok) return (sint)exitCode; + if (ok) return (sint)exitCode; + } if (log) - nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + { + std::string error = toString((uint)ret); + + if (ret == WAIT_FAILED) + { + error += "(" + formatErrorMessage(getLastError()) +")"; + } + + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' and error: %s", programName.c_str(), arguments.c_str(), error.c_str()); + } return -1; #else