diff options
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r-- | llvm/lib/Support/Unix/Signals.inc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index be05eabfb2e..5e0cde4a81e 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -82,12 +82,18 @@ using namespace llvm; static RETSIGTYPE SignalHandler(int Sig); // defined below. static RETSIGTYPE InfoSignalHandler(int Sig); // defined below. +static void DefaultPipeSignalFunction() { + exit(EX_IOERR); +} + using SignalHandlerFunctionType = void (*)(); /// The function to call if ctrl-c is pressed. static std::atomic<SignalHandlerFunctionType> InterruptFunction = ATOMIC_VAR_INIT(nullptr); static std::atomic<SignalHandlerFunctionType> InfoSignalFunction = ATOMIC_VAR_INIT(nullptr); +static std::atomic<SignalHandlerFunctionType> PipeSignalFunction = + ATOMIC_VAR_INIT(DefaultPipeSignalFunction); namespace { /// Signal-safe removal of files. @@ -363,7 +369,8 @@ static RETSIGTYPE SignalHandler(int Sig) { // Send a special return code that drivers can check for, from sysexits.h. if (Sig == SIGPIPE) - exit(EX_IOERR); + if (SignalHandlerFunctionType CurrentPipeFunction = PipeSignalFunction) + CurrentPipeFunction(); raise(Sig); // Execute the default handler. return; @@ -403,6 +410,11 @@ void llvm::sys::SetInfoSignalFunction(void (*Handler)()) { RegisterHandlers(); } +void llvm::sys::SetPipeSignalFunction(void (*Handler)()) { + PipeSignalFunction.exchange(Handler); + RegisterHandlers(); +} + // The public API bool llvm::sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { |