[PATCH 3/3] testbot/testagentd: Fix the console when redirecting stdin/out/err on Windows.

Francois Gouget fgouget at codeweavers.com
Thu Oct 31 11:03:23 CDT 2019


When When TestAgentd runs in --detach mode it does not have a console.
The child console processes still get a console but when using
STARTF_USESTDHANDLES the non-redirected stdin/out/err ifile handles
would not point to it. This appears to be because CreateProcess()
compares the STARTUPINFO handles with the parent's GetStdHandle() ones
and only reconnects them to the child console if they match.

So if the parent has no console the child inherits garbage values for
the GetStdHandle()s, that is GetFileType() returns FILE_TYPE_UNKNOWN for
those and their behavior is somewhat random. This would break some
kernel32:console STD_INPUT_HANDLE tests.

So when in --detach mode TestAgentd now creates a new console before
calling CreateProcess(). This resets stdin/out/err to point to the
console causing the child process to inherit proper handle values.
TestAgentd then detaches from the console which means it may just flash
on screen if starting a GUI application.

Increment the version so clients can check whether Run() redirections
are fully usable.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/src/testagentd/platform_windows.c | 8 +++++++-
 testbot/src/testagentd/testagentd.c       | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c
index ea6f03f80..057e8fc3c 100644
--- a/testbot/src/testagentd/platform_windows.c
+++ b/testbot/src/testagentd/platform_windows.c
@@ -29,9 +29,10 @@ struct child_t
     DWORD pid;
     HANDLE handle;
 };
-
 static struct list children = LIST_INIT(children);
 
+static BOOLEAN detached = FALSE;
+
 
 uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
 {
@@ -79,6 +80,8 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
     *(d-1) = '\0';
 
     /* Prepare the redirections */
+    if (detached)
+        AllocConsole();
     has_redirects = 0;
     for (i = 0; i < 3; i++)
     {
@@ -149,6 +152,8 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
     for (i = 0; i < 3; i++)
         if (redirects[i][0])
             CloseHandle(fhs[i]);
+    if (detached)
+        platform_detach_console();
 
     return pi.dwProcessId;
 }
@@ -692,6 +697,7 @@ void platform_detach_console(void)
     SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
     SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
     SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
+    detached = TRUE;
 }
 
 int platform_init(void)
diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c
index 2e06f4537..7c7a4130c 100644
--- a/testbot/src/testagentd/testagentd.c
+++ b/testbot/src/testagentd/testagentd.c
@@ -41,6 +41,7 @@
  * 1.7:  Add --show-restarts and the setproperty RPC.
  * 1.8:  Add the restart RPC, server.arg* properties, fix upgrades if >1
  *       server.
+ * 1.9:  Fix the console handling when redirecting stdin/out/err on Windows.
  */
 #define PROTOCOL_VERSION "testagentd 1.8"
 
-- 
2.20.1



More information about the wine-devel mailing list