From e6fb58a4921ce606ed6145ad99144dff8fe4b8d2 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 17 May 2016 13:30:58 -0400 Subject: [PATCH] Ignore SIGPIPE signals when writing to GSS socket. If the remote end of a GSS connection disconnects, attempts to write to the now-broken pipe result in a SIGPIPE signal. This unceremoniously exits. Instead, ignore those signals during the write() and let the error handling code deal gracefully with the broken pipe. --- gsscon/gsscon_common.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gsscon/gsscon_common.c b/gsscon/gsscon_common.c index fe559de..c391698 100755 --- a/gsscon/gsscon_common.c +++ b/gsscon/gsscon_common.c @@ -52,6 +52,8 @@ * or implied warranty. */ +#include + #include /* --------------------------------------------------------------------------- */ @@ -131,7 +133,14 @@ static int WriteBuffer (int inSocket, if (!err) { const char *ptr = inBuffer; do { - ssize_t count = write (inSocket, ptr, inBufferLength - bytesWritten); + ssize_t count; + + /* disable the SIGPIPE signal while we write so that we can handle a + * broken pipe error gracefully */ + signal(SIGPIPE, SIG_IGN); /* temporarily disable */ + count = write (inSocket, ptr, inBufferLength - bytesWritten); + signal(SIGPIPE, SIG_DFL); /* reenable */ + if (count < 0) { /* Try again on EINTR */ if (errno != EINTR) { err = errno; } @@ -142,7 +151,7 @@ static int WriteBuffer (int inSocket, } while (!err && (bytesWritten < inBufferLength)); } - if (err) { gsscon_print_error (err, "WritBuffer failed"); } + if (err) { gsscon_print_error (err, "WriteBuffer failed"); } return err; } -- 2.1.4