Commit 7337853ae2b58fbccea28e795996f47fe151b0c9

Authored by Stéphane Raimbault
1 parent fd892617

Install an ignore handler for SIGPIPE on *BSD to mimic MSG_NOSIGNAL

Original patch by Jason Oster
Showing 2 changed files with 15 additions and 0 deletions
1 libmodbus 2.9.3 (2011-01-XX) 1 libmodbus 2.9.3 (2011-01-XX)
2 ============================ 2 ============================
3 3
  4 +- Install an ignore handler for SIGPIPE on *BSD
  5 + Original patch by Jason Oster.
4 - Fix closing of Win32 socket. 6 - Fix closing of Win32 socket.
5 Reported by Petr Parýzek. 7 Reported by Petr Parýzek.
6 - Fix unit identifier not copied by the TCP server. 8 - Fix unit identifier not copied by the TCP server.
src/modbus-tcp.c
@@ -425,6 +425,19 @@ modbus_t* modbus_new_tcp(const char *ip, int port) @@ -425,6 +425,19 @@ modbus_t* modbus_new_tcp(const char *ip, int port)
425 modbus_t *ctx; 425 modbus_t *ctx;
426 modbus_tcp_t *ctx_tcp; 426 modbus_tcp_t *ctx_tcp;
427 427
  428 +#if defined(OS_BSD)
  429 + /* MSG_NOSIGNAL is unsupported on *BSD so we install an ignore
  430 + handler for SIGPIPE. */
  431 + struct sigaction sa;
  432 +
  433 + sa.sa_handler = SIG_IGN;
  434 + if (sigaction(SIGPIPE, &sa, NULL) < 0) {
  435 + /* The debug flag can't be set here... */
  436 + fprintf(stderr, "Coud not install SIGPIPE handler.\n");
  437 + return -1;
  438 + }
  439 +#endif
  440 +
428 ctx = (modbus_t *) malloc(sizeof(modbus_t)); 441 ctx = (modbus_t *) malloc(sizeof(modbus_t));
429 _modbus_init_common(ctx); 442 _modbus_init_common(ctx);
430 443