From 5a9fad1c65e374e3e9072f93bfa4cf14352ecea0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 14 Feb 2017 19:40:28 +0000 Subject: [PATCH 06/12] test-utils-glib: Wait for the killed process to exit Otherwise, removing transient service directories that are being watched by the dbus-daemon can fail with EAGAIN. Signed-off-by: Simon McVittie --- test/test-utils-glib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index 64703e8f..d748e10d 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -418,9 +418,25 @@ test_connect_to_bus_as_user (TestMainContext *ctx, #endif } +static void +pid_died (GPid pid, + gint status, + gpointer user_data) +{ + gboolean *result = user_data; + + g_assert (result != NULL); + g_assert (!*result); + *result = TRUE; +} + void test_kill_pid (GPid pid) { + gint died = FALSE; + + g_child_watch_add (pid, pid_died, &died); + #ifdef DBUS_WIN if (pid != NULL) TerminateProcess (pid, 1); @@ -428,6 +444,9 @@ test_kill_pid (GPid pid) if (pid > 0) kill (pid, SIGTERM); #endif + + while (!died) + g_main_context_iteration (NULL, TRUE); } static gboolean -- 2.11.0