[PATCH] testbot/testagentd: Detach from the console if given the --detach option.
Francois Gouget
fgouget at codeweavers.com
Thu Dec 7 21:29:25 CST 2017
This makes it possible to close the console without killing testagentd,
and to start the tests from a non-minimized window.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
This patch is already in use on about half of the TestBot's VMs to
avoid focus issues with some of the Direct3D tests.
testbot/src/testagentd/platform.h | 3 +++
testbot/src/testagentd/platform_unix.c | 15 +++++++++++++++
testbot/src/testagentd/platform_windows.c | 5 +++++
testbot/src/testagentd/testagentd.c | 11 ++++++++++-
4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/testbot/src/testagentd/platform.h b/testbot/src/testagentd/platform.h
index ea807fb6..84ab4917 100644
--- a/testbot/src/testagentd/platform.h
+++ b/testbot/src/testagentd/platform.h
@@ -58,6 +58,9 @@ typedef int SOCKET;
int platform_init(void);
+/* Detach from the console so closing it won't kill testagentd. */
+void platform_detach_console(void);
+
enum run_flags_t {
RUN_DNT = 1,
RUN_DNTRUNC_OUT = 2,
diff --git a/testbot/src/testagentd/platform_unix.c b/testbot/src/testagentd/platform_unix.c
index b27c0165..dcd4d69b 100644
--- a/testbot/src/testagentd/platform_unix.c
+++ b/testbot/src/testagentd/platform_unix.c
@@ -328,6 +328,21 @@ void ta_freeaddrinfo(struct addrinfo *addresses)
return freeaddrinfo(addresses);
}
+void platform_detach_console(void)
+{
+ pid_t pid;
+
+ pid = fork();
+ if (pid != 0)
+ exit(0);
+
+ /* Daemonize */
+ signal(SIGHUP, SIG_IGN);
+ pid = fork();
+ if (pid != 0)
+ exit(0);
+}
+
int platform_init(void)
{
struct sigaction sa, osa;
diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c
index 70272a65..1efac1c7 100644
--- a/testbot/src/testagentd/platform_windows.c
+++ b/testbot/src/testagentd/platform_windows.c
@@ -450,6 +450,11 @@ void ta_freeaddrinfo(struct addrinfo *addresses)
}
}
+void platform_detach_console(void)
+{
+ FreeConsole();
+}
+
int platform_init(void)
{
HMODULE hdll;
diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c
index fce28b27..5f0f54ca 100644
--- a/testbot/src/testagentd/testagentd.c
+++ b/testbot/src/testagentd/testagentd.c
@@ -1218,6 +1218,7 @@ int main(int argc, char** argv)
{
const char* p;
char** arg;
+ int opt_detach = 0;
char* opt_port = NULL;
char* opt_srchost = NULL;
struct addrinfo *addresses, *addrp;
@@ -1242,6 +1243,10 @@ int main(int argc, char** argv)
{
opt_debug = 1;
}
+ else if (strcmp(*arg, "--detach") == 0)
+ {
+ opt_detach = 1;
+ }
else if (strcmp(*arg, "--help") == 0)
{
opt_usage = 1;
@@ -1313,7 +1318,7 @@ int main(int argc, char** argv)
}
if (opt_usage)
{
- printf("Usage: %s [--debug] [--help] PORT [SRCHOST]\n", name0);
+ printf("Usage: %s [--debug] [--detach] [--help] PORT [SRCHOST]\n", name0);
printf("\n");
printf("Provides a simple way to send/receive files and to run scripts on this host.\n");
printf("\n");
@@ -1321,9 +1326,13 @@ int main(int argc, char** argv)
printf(" PORT The port to listen on for connections.\n");
printf(" SRCHOST If specified, only connections from this host will be accepted.\n");
printf(" --debug Prints detailed information about what happens.\n");
+ printf(" --detach Detach from the console / terminal. Note that on Windows you should\n");
+ printf(" combine this with start: start %s --detach ...\n", name0);
printf(" --help Shows this usage message.\n");
exit(0);
}
+ if (opt_detach)
+ platform_detach_console();
/* Bind to the host in a protocol neutral way */
#ifdef SOCK_CLOEXEC
--
2.15.0
More information about the wine-devel
mailing list