aboutsummaryrefslogtreecommitdiff
path: root/lib/System/Unix
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-02 02:14:22 +0000
committerChris Lattner <sabre@nondot.org>2005-08-02 02:14:22 +0000
commitfa8c292ebd893b3effef4ead9c88d261c628c340 (patch)
tree65defe9bd8790e8db4991f3f1e91d155a28b685a /lib/System/Unix
parente62321ac417fc894c15fa1420408a286b9a535d0 (diff)
Implement sys::SetInterruptFunction on Unix, stub it on win32 so that the
build will not fail git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r--lib/System/Unix/Signals.inc20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/System/Unix/Signals.inc b/lib/System/Unix/Signals.inc
index a9af969d5b..a643dbf972 100644
--- a/lib/System/Unix/Signals.inc
+++ b/lib/System/Unix/Signals.inc
@@ -24,6 +24,9 @@
namespace {
+/// InterruptFunction - The function to call if ctrl-c is pressed.
+void (*InterruptFunction)() = 0;
+
std::vector<std::string> *FilesToRemove = 0 ;
std::vector<llvm::sys::Path> *DirectoriesToRemove = 0;
@@ -116,8 +119,16 @@ RETSIGTYPE SignalHandler(int Sig) {
DirectoriesToRemove->pop_back();
}
- if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd)
- exit(1); // If this is an interrupt signal, exit the program
+ if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
+ if (InterruptFunction) {
+ void (*IF)() = InterruptFunction;
+ InterruptFunction = 0;
+ IF(); // run the interrupt function.
+ return;
+ } else {
+ exit(1); // If this is an interrupt signal, exit the program
+ }
+ }
// Otherwise if it is a fault (like SEGV) output the stacktrace to
// STDERR (if we can) and reissue the signal to die...
@@ -134,6 +145,11 @@ void RegisterHandler(int Signal) {
namespace llvm {
+void sys::SetInterruptFunction(void (*IF)()) {
+ InterruptFunction = IF;
+ RegisterHandler(SIGINT);
+}
+
// RemoveFileOnSignal - The public API
void sys::RemoveFileOnSignal(const sys::Path &Filename) {
if (FilesToRemove == 0)