diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 4c281a60be058a76a5cab1c5044e0e6304c0dbd7..7b91e403c33d37667407d4f427607976cc041139 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -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 diff --git a/ghc/rts/Signals.c b/ghc/rts/Signals.c index 7214cb45d8deb78ab04cdf67e9ef9acdf0fd73b2..6e5d859fda690784c0c31722ca4ff741c4f4603b 100644 --- a/ghc/rts/Signals.c +++ b/ghc/rts/Signals.c @@ -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 */ diff --git a/ghc/rts/Signals.h b/ghc/rts/Signals.h index 0d8a2221380a765fc510579aa20c616143e4a7ac..0127ce583503d53f0ab21b89bc8ee1b7ee5df24b 100644 --- a/ghc/rts/Signals.h +++ b/ghc/rts/Signals.h @@ -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)