Use case is the need to mask SIGPIPE
in pthreads that do their own write()
and/or SSL_write()
and have it compile on current POSIX-ish systems like Linux, macOS, BSD, etc. The typical approach on Linux is explained quite nicely here, and there is lots of good additional discussion on the topic here.
The typical signal(SIGPIPE, SIG_IGN)
does work everywhere I have tried, but (I believe) there should be a more surgical solution that avoids globally ignoring SIGPIPE
. It would also be nice to avoid platform specific pragma if possible.
The sigtimedwait()
function does not appear to exist in (current?) versions of macOS, so a cross platform solution does not look likely using that approach.
The sigwait()
function seems to exist everywhere, but that will block forever if the particular signal is not actually pending. So the next best approach appears to be to use sigpending()
to see what is pending, and then sigwait()
to service it, which both appear to be available.
What has me concerned is that there is virtually nothing (that I can find) written on this particular problem, which is usually a sign that I am missing something painfully obvious.
So, is pthread_sigmask()
/ sigpending()
/ sigwait()
/ pthread_sigmask()
a good choice for the above use case? Or are there (non?)obvious pitfalls I should be aware of?