From b3fdc72ae7ab79d8e74e8dbf0f4908b56bd5eabc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 13 Feb 2017 17:31:41 +0000 Subject: [PATCH 05/11] test_get_dbus_daemon: Take a custom XDG_RUNTIME_DIR as an argument Signed-off-by: Simon McVittie --- test/dbus-daemon-eavesdrop.c | 2 +- test/dbus-daemon.c | 2 +- test/monitor.c | 2 +- test/sd-activation.c | 2 +- test/test-utils-glib.c | 11 +++++++++-- test/test-utils-glib.h | 1 + test/uid-permissions.c | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c index 9dac06f2..be51f6ab 100644 --- a/test/dbus-daemon-eavesdrop.c +++ b/test/dbus-daemon-eavesdrop.c @@ -287,7 +287,7 @@ setup (Fixture *f, f->ge = NULL; dbus_error_init (&f->e); - address = test_get_dbus_daemon (NULL, TEST_USER_ME, &f->daemon_pid); + address = test_get_dbus_daemon (NULL, TEST_USER_ME, NULL, &f->daemon_pid); f->sender = test_connect_to_bus (f->ctx, address); dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index ba67f434..35538c68 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -173,7 +173,7 @@ setup (Fixture *f, } f->address = test_get_dbus_daemon (config ? config->config_file : NULL, - TEST_USER_ME, + TEST_USER_ME, NULL, &f->daemon_pid); if (f->address == NULL) diff --git a/test/monitor.c b/test/monitor.c index 6133721f..9446294d 100644 --- a/test/monitor.c +++ b/test/monitor.c @@ -450,7 +450,7 @@ setup (Fixture *f, dbus_error_init (&f->e); f->address = test_get_dbus_daemon (f->config ? f->config->config_file : NULL, - TEST_USER_ME, &f->daemon_pid); + TEST_USER_ME, NULL, &f->daemon_pid); if (f->address == NULL) return; diff --git a/test/sd-activation.c b/test/sd-activation.c index da63f7d4..b195bf72 100644 --- a/test/sd-activation.c +++ b/test/sd-activation.c @@ -247,7 +247,7 @@ setup (Fixture *f, f->address = test_get_dbus_daemon ( "valid-config-files/systemd-activation.conf", - TEST_USER_ME, &f->daemon_pid); + TEST_USER_ME, NULL, &f->daemon_pid); if (f->address == NULL) return; diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index ee286b98..5991b122 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -95,12 +95,14 @@ spawn_dbus_daemon (const gchar *binary, const gchar *configuration, const gchar *listen_address, TestUser user, + const gchar *runtime_dir, GPid *daemon_pid) { GError *error = NULL; GString *address; gint address_fd; GPtrArray *argv; + gchar **envp = g_get_environ (); #ifdef DBUS_UNIX const struct passwd *pwd = NULL; #endif @@ -158,6 +160,9 @@ spawn_dbus_daemon (const gchar *binary, #endif } + if (runtime_dir != NULL) + envp = g_environ_setenv (envp, "XDG_RUNTIME_DIR", runtime_dir, TRUE); + argv = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (argv, g_strdup (binary)); g_ptr_array_add (argv, g_strdup (configuration)); @@ -175,7 +180,7 @@ spawn_dbus_daemon (const gchar *binary, g_spawn_async_with_pipes (NULL, /* working directory */ (gchar **) argv->pdata, - NULL, /* envp */ + envp, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, #ifdef DBUS_UNIX child_setup, (gpointer) pwd, @@ -190,6 +195,7 @@ spawn_dbus_daemon (const gchar *binary, g_assert_no_error (error); g_ptr_array_free (argv, TRUE); + g_strfreev (envp); address = g_string_new (NULL); @@ -228,6 +234,7 @@ spawn_dbus_daemon (const gchar *binary, gchar * test_get_dbus_daemon (const gchar *config_file, TestUser user, + const gchar *runtime_dir, GPid *daemon_pid) { gchar *dbus_daemon; @@ -296,7 +303,7 @@ test_get_dbus_daemon (const gchar *config_file, else { address = spawn_dbus_daemon (dbus_daemon, arg, - listen_address, user, daemon_pid); + listen_address, user, runtime_dir, daemon_pid); } g_free (dbus_daemon); diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index acacee0a..4016f73f 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -69,6 +69,7 @@ void _test_assert_no_error (const DBusError *e, gchar *test_get_dbus_daemon (const gchar *config_file, TestUser user, + const gchar *runtime_dir, GPid *daemon_pid); DBusConnection *test_connect_to_bus (TestMainContext *ctx, diff --git a/test/uid-permissions.c b/test/uid-permissions.c index 57f7ec96..19a9aa46 100644 --- a/test/uid-permissions.c +++ b/test/uid-permissions.c @@ -60,7 +60,7 @@ setup (Fixture *f, dbus_error_init (&f->e); address = test_get_dbus_daemon (config ? config->config_file : NULL, - TEST_USER_MESSAGEBUS, + TEST_USER_MESSAGEBUS, NULL, &f->daemon_pid); if (address == NULL) -- 2.11.0