From 8a9f3798dd0442b480d3b3371bc0278f897c12c8 Mon Sep 17 00:00:00 2001 From: Christian Babeux Date: Tue, 27 Nov 2012 22:27:56 -0500 Subject: [PATCH] Cygwin: sigtimedwait workaround for SIGPIPE handling on wait pipe write sigtimedwait(3) is not available in Cygwin. To workaround this limitation, if a SIGPIPE is pending after a write(3), kill ourselve with SIGPIPE and use sigwaitinfo(3) to wait on delivery and effectively "discarding" the signal. --- libringbuffer/frontend_internal.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libringbuffer/frontend_internal.h b/libringbuffer/frontend_internal.h index 2d3b1071..9ff28e39 100644 --- a/libringbuffer/frontend_internal.h +++ b/libringbuffer/frontend_internal.h @@ -457,11 +457,20 @@ void lib_ring_buffer_check_deliver(const struct lttng_ust_lib_ring_buffer_config ret = write(wakeup_fd, "", 1); } while (ret == -1L && errno == EINTR); if (ret == -1L && errno == EPIPE && !sigpipe_was_pending) { - struct timespec timeout = { 0, 0 }; - do { - ret = sigtimedwait(&sigpipe_set, NULL, - &timeout); - } while (ret == -1L && errno == EINTR); + ret = sigpending(&pending_set); + assert(!ret); + + if (sigismember(&pending_set, SIGPIPE)) { + /* + * Kill ourselves with SIGPIPE and wait on + * delivery, thus effectively discarding it. + */ + pthread_t self = pthread_self(); + pthread_kill(self, SIGPIPE); + do { + ret = sigwaitinfo(&sigpipe_set, NULL); + } while (ret == -1L && errno == EINTR); + } } if (!sigpipe_was_pending) { ret = pthread_sigmask(SIG_SETMASK, &old_set, NULL); -- 2.34.1