From 2649515d3f3ba7deba9958fea4ef4b65132884a5 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Fri, 12 Oct 2018 17:22:07 +0000 Subject: [PATCH] [Support] exit with custom return code for SIGPIPE Summary: We tell the user to file a bug report on LLVM right now, and SIGPIPE isn't LLVM's fault so our error message is wrong. Allows frontends to detect SIGPIPE from writing to closed readers. This can be seen commonly from piping into head, tee, or split. Fixes PR25349, rdar://problem/14285346, b/77310947 Reviewers: jfb Reviewed By: jfb Subscribers: majnemer, kristina, llvm-commits, thakis, srhines Differential Revision: https://reviews.llvm.org/D53000 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344372 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Signals.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index de26695d64e..ad88d5e9690 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -47,6 +47,7 @@ #include "llvm/Support/raw_ostream.h" #include #include +#include #ifdef HAVE_BACKTRACE # include BACKTRACE_HEADER // For backtrace(). #endif @@ -334,6 +335,10 @@ static RETSIGTYPE SignalHandler(int Sig) { if (auto OldInterruptFunction = InterruptFunction.exchange(nullptr)) return OldInterruptFunction(); + // Send a special return code that drivers can check for, from sysexits.h. + if (Sig == SIGPIPE) + exit(EX_IOERR); + raise(Sig); // Execute the default handler. return; } -- 2.11.0