This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup] Propagate exit code of elevated process
- From: Jon Turney <jon dot turney at dronecode dot org dot uk>
- To: cygwin-apps at cygwin dot com
- Cc: Jon Turney <jon dot turney at dronecode dot org dot uk>
- Date: Sat, 7 Jul 2018 13:40:47 +0100
- Subject: [PATCH setup] Propagate exit code of elevated process
Propagate the exit code of elevated process, when --wait is used.
This addresses part of the problem about exit code noted in [1], although we
also need to audit that a non-zero exit code is reported in all error
situations.
[1] https://cygwin.com/ml/cygwin/2018-07/msg00020.html
Also report if starting the elevated child process failed.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
---
main.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/main.cc b/main.cc
index 9ca3f25..1374fb6 100644
--- a/main.cc
+++ b/main.cc
@@ -343,12 +343,16 @@ WinMain (HINSTANCE h,
if (ShellExecuteEx(&sei))
{
+ DWORD exitcode = 0;
/* Wait until child process is finished. */
if (WaitOption && sei.hProcess != NULL)
- WaitForSingleObject (sei.hProcess, INFINITE);
+ if (!WaitForSingleObject (sei.hProcess, INFINITE))
+ GetExitCodeProcess (sei.hProcess, &exitcode);
+ Logger ().setExitMsg (IDS_ELEVATED);
+ Logger ().exit (exitcode, false);
}
- Logger ().setExitMsg (IDS_ELEVATED);
- Logger ().exit (0, false);
+ Log (LOG_PLAIN) << "Starting elevated child process failed" << endLog;
+ Logger ().exit (1, false);
}
else
{
--
2.17.0