From 3b044d4296b1dffa5586658e152e1c7bd8144410 Mon Sep 17 00:00:00 2001 From: Thomas Pornin Date: Sun, 20 Nov 2016 16:23:00 +0100 Subject: [PATCH] SIGPIPE shall be ignored in most network-related cases. --- samples/client_basic.c | 6 ++++++ samples/server_basic.c | 6 ++++++ tools/client.c | 6 ++++++ tools/server.c | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/samples/client_basic.c b/samples/client_basic.c index d4f79fb..1609f43 100644 --- a/samples/client_basic.c +++ b/samples/client_basic.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -260,6 +261,11 @@ main(int argc, char *argv[]) path = "/"; } + /* + * Ignore SIGPIPE to avoid crashing in case of abrupt socket close. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the socket to the target server. */ diff --git a/samples/server_basic.c b/samples/server_basic.c index fdd801e..92c7d42 100644 --- a/samples/server_basic.c +++ b/samples/server_basic.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -278,6 +279,11 @@ main(int argc, char *argv[]) } port = argv[1]; + /* + * Ignore SIGPIPE to avoid crashing in case of abrupt socket close. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the server socket. */ diff --git a/tools/client.c b/tools/client.c index 2c2985f..552b7f9 100644 --- a/tools/client.c +++ b/tools/client.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -619,6 +620,11 @@ do_client(int argc, char *argv[]) br_ssl_engine_set_buffer(&cc.eng, iobuf, iobuf_len, bidi); br_ssl_client_reset(&cc, sni, 0); + /* + * We need to avoid SIGPIPE. + */ + signal(SIGPIPE, SIG_IGN); + /* * Connect to the peer. */ diff --git a/tools/server.c b/tools/server.c index 71cfa5d..c6978cf 100644 --- a/tools/server.c +++ b/tools/server.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1010,6 +1011,11 @@ do_server(int argc, char *argv[]) br_ssl_engine_set_buffer(&cc.eng, iobuf, iobuf_len, bidi); + /* + * We need to ignore SIGPIPE. + */ + signal(SIGPIPE, SIG_IGN); + /* * Open the server socket. */ -- 2.17.1