[project @ 1999-09-22 11:53:33 by sof]
authorsof <unknown>
Wed, 22 Sep 1999 11:53:33 +0000 (11:53 +0000)
committersof <unknown>
Wed, 22 Sep 1999 11:53:33 +0000 (11:53 +0000)
At startup time, install a SIGINT termination handler which calls
shutdownHaskellAndExit(), if invoked.

ghc/rts/RtsStartup.c
ghc/rts/Signals.c
ghc/rts/Signals.h

index 4c281a6..7b91e40 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsStartup.c,v 1.20 1999/09/15 13:45:20 simonmar Exp $
+ * $Id: RtsStartup.c,v 1.21 1999/09/22 11:53:33 sof Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -121,9 +121,11 @@ startupHaskell(int argc, char *argv[])
     /* Initialise the stats department */
     initStats();
 
-    /* Initialise the user signal handler set */
 #if !defined(mingw32_TARGET_OS) && !defined(PAR)
+    /* Initialise the user signal handler set */
     initUserSignals();
+    /* Set up handler to run on SIGINT */
+    init_shutdown_handler();
 #endif
  
     /* When the RTS and Prelude live in separate DLLs,
@@ -179,7 +181,7 @@ shutdownHaskell(void)
 
   /* stop the ticker */
   initialize_virtual_timer(0);
-
+  
 #if defined(PROFILING) || defined(DEBUG)
   endProfiling();
 #endif
index 7214cb4..6e5d859 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Signals.c,v 1.7 1999/07/14 13:39:46 simonmar Exp $
+ * $Id: Signals.c,v 1.8 1999/09/22 11:53:33 sof Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -245,4 +245,38 @@ start_signal_handlers(void)
 }
 #endif
 
+static void
+shutdown_handler(int sig)
+{
+  shutdownHaskellAndExit(EXIT_FAILURE);
+}
+
+/*
+ * The RTS installs a default signal handler for catching
+ * SIGINT, so that we can perform an orderly shutdown (finalising
+ * objects and flushing buffers etc.)
+ *
+ * Haskell code may install their own SIGINT handler, which is
+ * fine, provided they're so kind as to put back the old one
+ * when they de-install.
+ */
+void
+init_shutdown_handler()
+{
+    struct sigaction action,oact;
+
+    action.sa_handler = shutdown_handler;
+    sigemptyset(&action.sa_mask);
+    action.sa_flags = 0;
+    if (sigaction(SIGINT, &action, &oact) != 0) {
+      /* Oh well, at least we tried. */
+#ifdef DEBUG
+      fprintf(stderr, "init_shutdown_handler: failed to reg SIGINT handler");
+#endif
+    }
+}
+
+
+
+
 #endif /*! mingw32_TARGET_OS */
index 0d8a222..0127ce5 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Signals.h,v 1.3 1999/02/05 16:02:55 simonm Exp $
+ * $Id: Signals.h,v 1.4 1999/09/22 11:53:33 sof Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -22,6 +22,8 @@ extern void unblockUserSignals(void);
 
 extern void start_signal_handlers(void);
 
+extern void init_shutdown_handler(void);
+
 #else
 
 #define signals_pending() (rtsFalse)