if test x"$glib_cv_eventfd" = x"yes"; then
AC_DEFINE(HAVE_EVENTFD, 1, [we have the eventfd(2) system call])
fi
+AM_CONDITIONAL(HAVE_EVENTFD, [test "$glib_cv_eventfd" = "yes"])
dnl ****************************************
dnl *** GLib POLL* compatibility defines ***
TEST_PROGS += gwakeup
gwakeup_LDADD = $(progs_ldadd) $(top_builddir)/gthread/libgthread-2.0.la
+
+if HAVE_EVENTFD
+TEST_PROGS += gwakeup-fallback
+gwakeup_fallback_SOURCES = gwakeup.c
+gwakeup_fallback_CFLAGS = $(AM_CFLAGS) -DTEST_EVENTFD_FALLBACK
+gwakeup_fallback_LDADD = $(progs_ldadd) $(top_builddir)/gthread/libgthread-2.0.la
+endif
#include <unistd.h>
#include <glib.h>
+#ifdef TEST_EVENTFD_FALLBACK
+ #include <errno.h>
+
+ static gboolean we_broke_eventfd;
+
+ /* We interpose over the eventfd() call in the libc to ensure that a
+ * failed call to eventfd() gives us a working fallback.
+ *
+ * We need to do this because older kernel versions don't have eventfd
+ * support, and some of them have eventfd but without support for some
+ * of the flags we use.
+ *
+ * We use the we_broke_eventfd boolean to make sure that it actually
+ * worked.
+ */
+ int eventfd (void) {
+ we_broke_eventfd = TRUE;
+ errno = EINVAL;
+
+ return -1;
+ }
+ #define TESTNAME_SUFFIX "-fallback"
+#else
+ #define TESTNAME_SUFFIX ""
+#endif
+
#ifdef _WIN32
void alarm (int sec) { }
#endif
/* prevent the test from deadlocking */
alarm (30);
+#ifdef TEST_EVENTFD_FALLBACK
+ we_broke_eventfd = FALSE;
+#endif
+
wakeup = g_wakeup_new ();
g_assert (!check_signaled (wakeup));
+#ifdef TEST_EVENTFD_FALLBACK
+ /* make sure our interposed eventfd call worked */
+ g_assert (we_broke_eventfd);
+#endif
+
g_wakeup_signal (wakeup);
g_assert (check_signaled (wakeup));
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/gwakeup/semantics", test_semantics);
- g_test_add_func ("/gwakeup/threaded", test_threaded);
+ g_test_add_func ("/gwakeup/semantics" TESTNAME_SUFFIX, test_semantics);
+ g_test_add_func ("/gwakeup/threaded" TESTNAME_SUFFIX, test_threaded);
return g_test_run ();
}