]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sd-activation test: Create and destroy a temporary XDG_RUNTIME_DIR
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 14 Feb 2017 19:03:44 +0000 (19:03 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 21 Feb 2017 13:23:34 +0000 (13:23 +0000)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
test/sd-activation.c
test/test-utils-glib.c
test/test-utils-glib.h

index 086edaa9992724a47d027c1461bfae20e483a4f9..71a6da25c2dd55bfc4c2a4da55149c2298556234 100644 (file)
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <sys/types.h>
 
+#include <glib/gstdio.h>
+
 #if defined(HAVE_APPARMOR_2_10) && defined(DBUS_TEST_APPARMOR_ACTIVATION)
 #include <sys/apparmor.h>
 #endif
@@ -62,6 +64,8 @@ typedef struct {
     const char *activated_name;
     DBusMessage *activated_message;
     dbus_bool_t activated_filter_added;
+
+    gchar *tmp_runtime_dir;
 } Fixture;
 
 typedef struct
@@ -211,6 +215,16 @@ static void
 setup (Fixture *f,
     gconstpointer context G_GNUC_UNUSED)
 {
+#if defined(DBUS_TEST_APPARMOR_ACTIVATION) && defined(HAVE_APPARMOR_2_10)
+  aa_features *features;
+#endif
+
+  f->ge = NULL;
+  dbus_error_init (&f->e);
+
+  f->tmp_runtime_dir = g_dir_make_tmp ("dbus-daemon-test.XXXXXX", &f->ge);
+  g_assert_no_error (f->ge);
+
 #if defined(DBUS_TEST_APPARMOR_ACTIVATION) && !defined(HAVE_APPARMOR_2_10)
 
   g_test_skip ("AppArmor support not compiled or AppArmor 2.10 unavailable");
@@ -219,8 +233,6 @@ setup (Fixture *f,
 #else
 
 #if defined(DBUS_TEST_APPARMOR_ACTIVATION)
-  aa_features *features;
-
   if (!aa_is_enabled ())
     {
       g_test_message ("aa_is_enabled() -> %s", g_strerror (errno));
@@ -247,12 +259,9 @@ setup (Fixture *f,
 
   f->ctx = test_main_context_get ();
 
-  f->ge = NULL;
-  dbus_error_init (&f->e);
-
   f->address = test_get_dbus_daemon (
       "valid-config-files/systemd-activation.conf",
-      TEST_USER_ME, NULL, &f->daemon_pid);
+      TEST_USER_ME, f->tmp_runtime_dir, &f->daemon_pid);
 
   if (f->address == NULL)
     return;
@@ -820,6 +829,13 @@ teardown (Fixture *f,
     test_main_context_unref (f->ctx);
 
   g_free (f->address);
+
+  if (f->tmp_runtime_dir != NULL)
+    {
+      test_rmdir_if_exists (f->tmp_runtime_dir);
+
+      g_free (f->tmp_runtime_dir);
+    }
 }
 
 static const Config deny_send_tests[] =
index fac5ddaf79af1cec6f2bc4f6ddf71b671ec0829f..e60a40d36e14a83710381da9140197a38553703f 100644 (file)
@@ -546,3 +546,27 @@ test_rmdir_must_exist (const gchar *path)
                g_strerror (saved_errno));
     }
 }
+
+/*
+ * Delete empty directory @path, with a retry loop if the system call is
+ * interrupted by an async signal. If @path does not exist, ignore.
+ */
+void
+test_rmdir_if_exists (const gchar *path)
+{
+  while (g_remove (path) != 0)
+    {
+      int saved_errno = errno;
+
+      if (saved_errno == ENOENT)
+        return;
+
+#ifdef G_OS_UNIX
+      if (saved_errno == EINTR)
+        continue;
+#endif
+
+      g_error ("Unable to remove directory \"%s\": %s", path,
+               g_strerror (saved_errno));
+    }
+}
index e62ef3d63b79c9ad1655722051ff0e306226c141..d29c58da965d2baec3fb1ee641d6e54aad81545b 100644 (file)
@@ -94,5 +94,6 @@ static inline void my_test_skip (const gchar *s)
 
 void test_remove_if_exists (const gchar *path);
 void test_rmdir_must_exist (const gchar *path);
+void test_rmdir_if_exists (const gchar *path);
 
 #endif