aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/Unix/Signals.inc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/Unix/Signals.inc')
-rw-r--r--lib/Support/Unix/Signals.inc15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc
index 634c16aa36c7..5e0cde4a81ed 100644
--- a/lib/Support/Unix/Signals.inc
+++ b/lib/Support/Unix/Signals.inc
@@ -43,7 +43,6 @@
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/SaveAndRestore.h"
-#include "llvm/Support/UniqueLock.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <string>
@@ -83,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.
@@ -364,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;
@@ -404,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) {