/* -----------------------------------------------------------------------------
- * $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
*
/* 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,
/* stop the ticker */
initialize_virtual_timer(0);
-
+
#if defined(PROFILING) || defined(DEBUG)
endProfiling();
#endif
/* -----------------------------------------------------------------------------
- * $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
*
}
#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 */
/* -----------------------------------------------------------------------------
- * $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
*
extern void start_signal_handlers(void);
+extern void init_shutdown_handler(void);
+
#else
#define signals_pending() (rtsFalse)