Commit 7337853ae2b58fbccea28e795996f47fe151b0c9
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
NEWS
src/modbus-tcp.c
| ... | ... | @@ -425,6 +425,19 @@ modbus_t* modbus_new_tcp(const char *ip, int port) |
| 425 | 425 | modbus_t *ctx; |
| 426 | 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 | 441 | ctx = (modbus_t *) malloc(sizeof(modbus_t)); |
| 429 | 442 | _modbus_init_common(ctx); |
| 430 | 443 | ... | ... |