From 38368e0d164dba64cfc33bbe770595967bee971f Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 26 Jan 2017 23:53:55 +0100 Subject: [PATCH] Fix endless loop in case spawned process exits in spawn_dbus_daemon(). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99512 --- test/test-utils-glib.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index f7d60eb..95618cb 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -105,6 +105,7 @@ spawn_dbus_daemon (const gchar *binary, const struct passwd *pwd = NULL; #endif char *envp[2] = { "DBUS_VERBOSE=1", NULL }; + gboolean is_running = TRUE; if (!g_getenv ("DBUS_VERBOSE") || *g_getenv ("DBUS_VERBOSE") == '0') envp[0] = NULL; @@ -200,7 +201,7 @@ spawn_dbus_daemon (const gchar *binary, /* polling until the dbus-daemon writes out its address is a bit stupid, * but at least it's simple, unlike dbus-launch... in principle we could * use select() here, but life's too short */ - while (1) + while (is_running) { gssize bytes; gchar buf[4096]; @@ -222,11 +223,12 @@ spawn_dbus_daemon (const gchar *binary, } g_usleep (G_USEC_PER_SEC / 10); + is_running = test_check_pid (daemon_pid); } g_close (address_fd, NULL); - return g_string_free (address, FALSE); + return is_running ? g_string_free (address, FALSE) : 0; } @@ -444,6 +446,19 @@ test_kill_pid (GPid pid) #endif } +gboolean +test_check_pid (GPid pid) +{ +#ifdef DBUS_WIN + HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid); + DWORD ret = WaitForSingleObject(process, 0); + CloseHandle(process); + return ret == WAIT_TIMEOUT; +#else + return getpgid(pid) >= 0; +#endif +} + static gboolean time_out (gpointer data) { -- 2.6.6