From d8cdb57efadf380fc750d368aede8cf24259ca81 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Sun, 14 Jul 2013 12:33:38 +0700 Subject: [PATCH] HAL_SITL: Attempting to avoid SIGPIPE on all platforms --- libraries/AP_HAL_AVR_SITL/SITL_State.cpp | 2 ++ libraries/AP_HAL_AVR_SITL/UARTDriver.cpp | 12 ++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/AP_HAL_AVR_SITL/SITL_State.cpp b/libraries/AP_HAL_AVR_SITL/SITL_State.cpp index b2dc1e6eef..bb927f1941 100644 --- a/libraries/AP_HAL_AVR_SITL/SITL_State.cpp +++ b/libraries/AP_HAL_AVR_SITL/SITL_State.cpp @@ -97,6 +97,8 @@ void SITL_State::_parse_command_line(int argc, char * const argv[]) int opt; signal(SIGFPE, _sig_fpe); + // No-op SIGPIPE handler + signal(SIGPIPE, SIG_IGN); setvbuf(stdout, (char *)0, _IONBF, 0); setvbuf(stderr, (char *)0, _IONBF, 0); diff --git a/libraries/AP_HAL_AVR_SITL/UARTDriver.cpp b/libraries/AP_HAL_AVR_SITL/UARTDriver.cpp index fca750a119..ecd7920bc6 100644 --- a/libraries/AP_HAL_AVR_SITL/UARTDriver.cpp +++ b/libraries/AP_HAL_AVR_SITL/UARTDriver.cpp @@ -40,14 +40,6 @@ using namespace AVR_SITL; -// On OSX, MSG_NOSIGNAL doesn't exist. The equivalent is to set SO_NOSIGPIPE -// in setsockopt for the socket. However, if we just skip that, and don't use -// MSG_NOSIGNAL, everything seems to work fine and SIGPIPE doesn't seem to be -// generated. -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - bool SITLUARTDriver::_console; /* UARTDriver method implementations */ @@ -139,7 +131,7 @@ int16_t SITLUARTDriver::read(void) return ::read(0, &c, 1); } - int n = recv(_fd, &c, 1, MSG_DONTWAIT | MSG_NOSIGNAL); + int n = recv(_fd, &c, 1, MSG_DONTWAIT); if (n <= 0) { // the socket has reached EOF close(_fd); @@ -160,7 +152,7 @@ void SITLUARTDriver::flush(void) size_t SITLUARTDriver::write(uint8_t c) { - int flags = MSG_NOSIGNAL; + int flags = 0; _check_connection(); if (!_connected) { return 0;