From 1862438e1e29c4f4069d9ca43b25445078547faa Mon Sep 17 00:00:00 2001 From: sof Date: Wed, 22 Sep 1999 11:53:33 +0000 Subject: [PATCH] [project @ 1999-09-22 11:53:33 by sof] At startup time, install a SIGINT termination handler which calls shutdownHaskellAndExit(), if invoked. --- ghc/rts/RtsStartup.c | 8 +++++--- ghc/rts/Signals.c | 36 +++++++++++++++++++++++++++++++++++- ghc/rts/Signals.h | 4 +++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 4c281a6..7b91e40 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 7214cb4..6e5d859 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 0d8a222..0127ce5 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) -- 1.7.10.4