From 7337853ae2b58fbccea28e795996f47fe151b0c9 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Thu, 6 Jan 2011 08:25:49 +0100 Subject: [PATCH] Install an ignore handler for SIGPIPE on *BSD to mimic MSG_NOSIGNAL --- NEWS | 2 ++ src/modbus-tcp.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/NEWS b/NEWS index b31a221..f9cd880 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ libmodbus 2.9.3 (2011-01-XX) ============================ +- Install an ignore handler for SIGPIPE on *BSD + Original patch by Jason Oster. - Fix closing of Win32 socket. Reported by Petr Parýzek. - Fix unit identifier not copied by the TCP server. diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 50d3624..aa4e3c6 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -425,6 +425,19 @@ modbus_t* modbus_new_tcp(const char *ip, int port) modbus_t *ctx; modbus_tcp_t *ctx_tcp; +#if defined(OS_BSD) + /* MSG_NOSIGNAL is unsupported on *BSD so we install an ignore + handler for SIGPIPE. */ + struct sigaction sa; + + sa.sa_handler = SIG_IGN; + if (sigaction(SIGPIPE, &sa, NULL) < 0) { + /* The debug flag can't be set here... */ + fprintf(stderr, "Coud not install SIGPIPE handler.\n"); + return -1; + } +#endif + ctx = (modbus_t *) malloc(sizeof(modbus_t)); _modbus_init_common(ctx); -- libgit2 0.21.4