From: Christian Babeux Date: Wed, 28 Nov 2012 03:27:56 +0000 (-0500) Subject: Cygwin: sigtimedwait workaround for SIGPIPE handling on wait pipe write X-Git-Url: http://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=8a9f3798dd0442b480d3b3371bc0278f897c12c8 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. --- 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);