+ if (ret == -1L && errno == EPIPE && !sigpipe_was_pending) {
+ 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);
+ assert(!ret);
+ }