Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/src/testagentd/platform_windows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c index acd0138d4..b3db635e1 100644 --- a/testbot/src/testagentd/platform_windows.c +++ b/testbot/src/testagentd/platform_windows.c @@ -112,7 +112,7 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects) free(cmdline); while (i > 0) { - if (fhs[i] != INVALID_HANDLE_VALUE) + if (redirects[i][0] && fhs[i] != INVALID_HANDLE_VALUE) CloseHandle(fhs[i]); i--; }
GetStdHandle() still returns the pseudo handles for the closed console except they obviously don't work. So reset them to avoid confusion.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/src/testagentd/platform_windows.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c index b3db635e1..ea6f03f80 100644 --- a/testbot/src/testagentd/platform_windows.c +++ b/testbot/src/testagentd/platform_windows.c @@ -689,6 +689,9 @@ void ta_freeaddrinfo(struct addrinfo *addresses) void platform_detach_console(void) { FreeConsole(); + SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE); + SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE); + SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE); }
int platform_init(void)
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@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"