/* 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)
/* 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)
#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>
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));
+ }
+}