From 7d4e3714d04df944dbe7c9dba335e5d1f6d0e77b Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Tue, 5 Feb 2008 12:34:39 +0600 Subject: [PATCH] Ignore SIGPIPE. --- redsocks.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/redsocks.c b/redsocks.c index b5eee9e..63dfae2 100644 --- a/redsocks.c +++ b/redsocks.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -589,11 +590,19 @@ static int redsocks_init() int error; int on = 1; int fd = -1; + struct sigaction sa = { }, sa_old = { }; + + sa.sa_handler = SIG_IGN; + sa.sa_flags = SA_RESTART; + if (sigaction(SIGPIPE, &sa, &sa_old) == -1) { + log_errno("sigaction"); + return -1; + } fd = socket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { log_errno("socket"); - return -1; + goto fail; } error = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); @@ -637,6 +646,9 @@ fail: if (fd != -1) { close(fd); } + + // that was the first resource allocation, it return's on failure, not goto-fail's + sigaction(SIGPIPE, &sa_old, NULL); return -1; }