From 50dc1f5b71f7e0e4ba628904b9a47d9f9d875b3e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 31 Jul 2014 10:31:17 +0200 Subject: Restore default SIGPIPE handler before invoking ‘man’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes NixOS/nixpkgs#3410. --- src/libutil/util.cc | 10 ++++++++++ src/libutil/util.hh | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index aa9d99ec3353..f762b79c24da 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -927,6 +927,16 @@ void closeOnExec(int fd) } +void restoreSIGPIPE() +{ + struct sigaction act, oact; + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + if (sigaction(SIGPIPE, &act, &oact)) throw SysError("resetting SIGPIPE"); +} + + ////////////////////////////////////////////////////////////////////// diff --git a/src/libutil/util.hh b/src/libutil/util.hh index ad0d377a4f5e..64250c522a52 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -273,6 +273,10 @@ void closeMostFDs(const set & exceptions); /* Set the close-on-exec flag for the given file descriptor. */ void closeOnExec(int fd); +/* Restore default handling of SIGPIPE, otherwise some programs will + randomly say "Broken pipe". */ +void restoreSIGPIPE(); + /* User interruption. */ -- cgit 1.4.1