|
@@ -82,12 +82,18 @@ using namespace llvm;
|
|
static RETSIGTYPE SignalHandler(int Sig); // defined below.
|
|
static RETSIGTYPE SignalHandler(int Sig); // defined below.
|
|
static RETSIGTYPE InfoSignalHandler(int Sig); // defined below.
|
|
static RETSIGTYPE InfoSignalHandler(int Sig); // defined below.
|
|
|
|
|
|
|
|
+static void DefaultPipeSignalFunction() {
|
|
|
|
+ exit(EX_IOERR);
|
|
|
|
+}
|
|
|
|
+
|
|
using SignalHandlerFunctionType = void (*)();
|
|
using SignalHandlerFunctionType = void (*)();
|
|
/// The function to call if ctrl-c is pressed.
|
|
/// The function to call if ctrl-c is pressed.
|
|
static std::atomic<SignalHandlerFunctionType> InterruptFunction =
|
|
static std::atomic<SignalHandlerFunctionType> InterruptFunction =
|
|
ATOMIC_VAR_INIT(nullptr);
|
|
ATOMIC_VAR_INIT(nullptr);
|
|
static std::atomic<SignalHandlerFunctionType> InfoSignalFunction =
|
|
static std::atomic<SignalHandlerFunctionType> InfoSignalFunction =
|
|
ATOMIC_VAR_INIT(nullptr);
|
|
ATOMIC_VAR_INIT(nullptr);
|
|
|
|
+static std::atomic<SignalHandlerFunctionType> PipeSignalFunction =
|
|
|
|
+ ATOMIC_VAR_INIT(DefaultPipeSignalFunction);
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
/// Signal-safe removal of files.
|
|
/// 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.
|
|
// Send a special return code that drivers can check for, from sysexits.h.
|
|
if (Sig == SIGPIPE)
|
|
if (Sig == SIGPIPE)
|
|
- exit(EX_IOERR);
|
|
|
|
|
|
+ if (SignalHandlerFunctionType CurrentPipeFunction = PipeSignalFunction)
|
|
|
|
+ CurrentPipeFunction();
|
|
|
|
|
|
raise(Sig); // Execute the default handler.
|
|
raise(Sig); // Execute the default handler.
|
|
return;
|
|
return;
|
|
@@ -403,6 +410,11 @@ void llvm::sys::SetInfoSignalFunction(void (*Handler)()) {
|
|
RegisterHandlers();
|
|
RegisterHandlers();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void llvm::sys::SetPipeSignalFunction(void (*Handler)()) {
|
|
|
|
+ PipeSignalFunction.exchange(Handler);
|
|
|
|
+ RegisterHandlers();
|
|
|
|
+}
|
|
|
|
+
|
|
// The public API
|
|
// The public API
|
|
bool llvm::sys::RemoveFileOnSignal(StringRef Filename,
|
|
bool llvm::sys::RemoveFileOnSignal(StringRef Filename,
|
|
std::string* ErrMsg) {
|
|
std::string* ErrMsg) {
|