[PATCH setup] Propagate exit code of elevated process

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH setup] Propagate exit code of elevated process

Jon TURNEY
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 <[hidden email]>
---
 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

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH setup] Propagate exit code of elevated process

Ken Brown-6
On 7/7/2018 8:40 AM, Jon Turney wrote:
> 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.

I haven't done a complete audit, but I did happen to spot one place that
needs attention.  See the comment (made by you in 2010) in
PostInstallResultsPage::OnUnattended().

Ken