aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-10-14 12:43:16 +0200
committerMartin Willi <martin@revosec.ch>2014-10-14 16:34:44 +0200
commit76dc329e478e73840da02ba32d97eb8056ff59c3 (patch)
treefc404488f983292e6ea454754eeb10a3032e6ebf
parentbdfbecb3e638f793211b5e0eabf6e469ecedc429 (diff)
downloadstrongswan-76dc329e.tar.bz2
strongswan-76dc329e.tar.xz
thread: Test for pending cancellation requests before select()ing on OS X
This fixes some vici test cases on OS X, where the test thread tries to cancel the watcher thread during cleanup, but fails as select() does not honor the pre-issued cancellation request.
-rw-r--r--src/libstrongswan/threading/thread.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libstrongswan/threading/thread.h b/src/libstrongswan/threading/thread.h
index 8d3c30e9b..6abb83411 100644
--- a/src/libstrongswan/threading/thread.h
+++ b/src/libstrongswan/threading/thread.h
@@ -189,4 +189,32 @@ void threads_init();
*/
void threads_deinit();
+
+#ifdef __APPLE__
+
+/*
+ * While select() is a cancellation point, it seems that OS X does not honor
+ * pending cancellation points when entering the function. We manually test for
+ * and honor pending cancellation requests, but this obviously can't prevent
+ * some race conditions where the the cancellation happens after the check,
+ * but before the select.
+ */
+static inline int precancellable_select(int nfds, fd_set *restrict readfds,
+ fd_set *restrict writefds, fd_set *restrict errorfds,
+ struct timeval *restrict timeout)
+{
+ if (thread_cancelability(TRUE))
+ {
+ thread_cancellation_point();
+ }
+ else
+ {
+ thread_cancelability(FALSE);
+ }
+ return select(nfds, readfds, writefds, errorfds, timeout);
+}
+#define select precancellable_select
+
+#endif /* __APPLE__ */
+
#endif /** THREADING_THREAD_H_ @} */