]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tests: Wrap file-deletion functions to handle EINTR
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 14 Feb 2017 19:49:46 +0000 (19:49 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 20 Feb 2017 16:48:23 +0000 (16:48 +0000)
The GLib functions we're using don't, and it seems to be possible to be
interrupted during cleanup for our tests.

Windows apparently has and uses ENOENT for _unlink(), so just do the
same on Windows there; but EINTR is very much a POSIX thing, so ignore
that on Windows.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: add Windows fixes from a later commit, also reviewed by Philip]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
test/dbus-daemon.c
test/loopback.c
test/test-utils-glib.c
test/test-utils-glib.h

index 35538c686aac3f569b05c1698eb59b64350c8d5d..d0b44d72cb114f18b8916b520e3aa787ee23261a 100644 (file)
@@ -1085,10 +1085,11 @@ teardown (Fixture *f,
 
       /* the socket may exist */
       path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir);
-      g_assert (g_remove (path) == 0 || errno == ENOENT);
+
+      test_remove_if_exists (path);
       g_free (path);
       /* there shouldn't be anything else in there */
-      g_assert_cmpint (g_rmdir (f->tmp_runtime_dir), ==, 0);
+      test_rmdir_must_exist (f->tmp_runtime_dir);
 
       /* we're relying on being single-threaded for this to be safe */
       if (f->saved_runtime_dir != NULL)
index bf0542aa06a6148ac31efece32bc095bac51a54e..5232a09a54a2d71ab11ad0f468e22e739db780d6 100644 (file)
@@ -332,10 +332,10 @@ teardown_runtime (Fixture *f,
 
   /* the socket may exist */
   path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir);
-  g_assert (g_remove (path) == 0 || errno == ENOENT);
+  test_remove_if_exists (path);
   g_free (path);
   /* there shouldn't be anything else in there */
-  g_assert_cmpint (g_rmdir (f->tmp_runtime_dir), ==, 0);
+  test_rmdir_must_exist (f->tmp_runtime_dir);
 
   /* we're relying on being single-threaded for this to be safe */
   if (f->saved_runtime_dir != NULL)
index f90244c3f68419a5cb089749a78e6625c073c6b4..c5059edbec4cbffd3f5a1ebc94e18e477d0d8219 100644 (file)
 #include <config.h>
 #include "test-utils-glib.h"
 
+#include <errno.h>
 #include <string.h>
 
 #ifdef DBUS_WIN
 # include <io.h>
 # include <windows.h>
 #else
-# include <errno.h>
 # include <signal.h>
 # include <unistd.h>
 # include <sys/types.h>
@@ -481,3 +481,49 @@ test_progress (char symbol)
   if (g_test_verbose () && isatty (1))
     g_print ("%c", symbol);
 }
+
+/*
+ * Delete @path, with a retry loop if the system call is interrupted by
+ * an async signal. If @path does not exist, ignore; otherwise, it is
+ * required to be a non-directory.
+ */
+void
+test_remove_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 file \"%s\": %s", path,
+               g_strerror (saved_errno));
+    }
+}
+
+/*
+ * Delete empty directory @path, with a retry loop if the system call is
+ * interrupted by an async signal. @path is required to exist.
+ */
+void
+test_rmdir_must_exist (const gchar *path)
+{
+  while (g_remove (path) != 0)
+    {
+      int saved_errno = errno;
+
+#ifdef G_OS_UNIX
+      if (saved_errno == EINTR)
+        continue;
+#endif
+
+      g_error ("Unable to remove directory \"%s\": %s", path,
+               g_strerror (saved_errno));
+    }
+}
index 4016f73f70c841e5cc55bb7f30473b26c9a677df..e62ef3d63b79c9ad1655722051ff0e306226c141 100644 (file)
@@ -92,4 +92,7 @@ static inline void my_test_skip (const gchar *s)
 }
 #endif
 
+void test_remove_if_exists (const gchar *path);
+void test_rmdir_must_exist (const gchar *path);
+
 #endif