From 034f89d824c8627b74afeb7ded3727e4eebfc6ab Mon Sep 17 00:00:00 2001 From: rob-the-dude <43481893+rob-the-dude@users.noreply.github.com> Date: Wed, 27 May 2020 13:08:36 -0700 Subject: [PATCH] [posix] some platforms don't support MSG_NOSIGNAL (#4996) On platforms that have SO_NOSIGPIPE, use that to achieve the same result. On platforms that have neither, emit a compile-time warning -- you may still receive the signal on those systems. --- src/posix/platform/uart.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/uart.cpp b/src/posix/platform/uart.cpp index 0fd572759..f584ec499 100644 --- a/src/posix/platform/uart.cpp +++ b/src/posix/platform/uart.cpp @@ -299,10 +299,27 @@ void platformUartProcess(const fd_set *aReadFdSet, const fd_set *aWriteFdSet, co { #if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE // Don't die on SIGPIPE +#if !defined(MSG_NOSIGNAL) + // some platforms (mac OS, Solaris) don't have MSG_NOSIGNAL + // SOME of those (mac OS, but NOT Solaris) support SO_NOSIGPIPE + // if we have SO_NOSIGPIPE, then set it. otherwise, we're going + // to simply ignore it. +#if defined(SO_NOSIGPIPE) + int err; + int flag; + + flag = 1; + err = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &flag, sizeof(flag)); + VerifyOrDie(err == 0, OT_EXIT_ERROR_ERRNO); +#else +#warning "no support for MSG_NOSIGNAL or SO_NOSIGPIPE" +#endif +#define MSG_NOSIGNAL 0 +#endif // !defined(MSG_NOSIGNAL) rval = send(fd, sWriteBuffer, sWriteLength, MSG_NOSIGNAL); #else rval = write(fd, sWriteBuffer, sWriteLength); -#endif +#endif // OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE if (rval < 0) {