Mercurial > hg > octave-nkf
diff src/sighandlers.cc @ 4449:e2c91da0aa16
[project @ 2003-07-09 02:21:11 by jwe]
author | jwe |
---|---|
date | Wed, 09 Jul 2003 02:21:11 +0000 |
parents | c1f6200b5f0e |
children | f6d6335c08f6 |
line wrap: on
line diff
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -60,6 +60,14 @@ // TRUE means we should try to enter the debugger on SIGINT. static bool Vdebug_on_interrupt = false; +// Allow users to avoid writing octave-core for SIGHUP (sent by +// closing gnome-terminal, for example). Note that this variable has +// no effect if Vcrash_dumps_octave_core is FALSE. +static bool Vsighup_dumps_octave_core; + +// Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. +static bool Vsigterm_dumps_octave_core; + #if RETSIGTYPE == void #define SIGHANDLER_RETURN(status) return #else @@ -234,6 +242,44 @@ #endif /* defined(__alpha__) */ #endif /* defined(SIGFPE) */ +#if defined (SIGHUP) || defined (SIGTERM) +static RETSIGTYPE +sig_hup_or_term_handler (int sig) +{ + MAYBE_ACK_SIGNAL (sig); + + MAYBE_REINSTALL_SIGHANDLER (sig, sig_hup_or_term_handler); + + switch (sig) + { +#if defined (SIGHUP) + case SIGHUP: + { + if (Vsighup_dumps_octave_core) + save_user_variables (); + } + break; +#endif + +#if defined (SIGTERM) + case SIGTERM: + { + if (Vsigterm_dumps_octave_core) + save_user_variables (); + } + break; +#endif + + default: + break; + } + + clean_up_and_exit (0); + + SIGHANDLER_RETURN (0); +} +#endif + #if 0 #if defined (SIGWINCH) static RETSIGTYPE @@ -404,7 +450,7 @@ #endif #ifdef SIGHUP - octave_set_signal_handler (SIGHUP, generic_sig_handler); + octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); #endif #ifdef SIGILL @@ -451,7 +497,7 @@ #endif #ifdef SIGTERM - octave_set_signal_handler (SIGTERM, generic_sig_handler); + octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); #endif #ifdef SIGTRAP @@ -771,6 +817,22 @@ return 0; } +static int +sighup_dumps_octave_core (void) +{ + Vsighup_dumps_octave_core = check_preference ("sighup_dumps_octave_core"); + + return 0; +} + +static int +sigterm_dumps_octave_core (void) +{ + Vsigterm_dumps_octave_core = check_preference ("sigterm_dumps_octave_core"); + + return 0; +} + void symbols_of_sighandlers (void) { @@ -784,6 +846,24 @@ The default value is 0.\n\ @end defvr"); + DEFVAR (sighup_dumps_octave_core, true, sighup_dumps_octave_core, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} sighup_dumps_octave_core\n\ +If this variable is set to a nonzero value and\n\ +@code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ +current variables the the file \"octave-core\" if it receives a\n\ +hangup signal. The default value is 1.\n\ +@end defvr"); + + DEFVAR (sigterm_dumps_octave_core, true, sigterm_dumps_octave_core, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} sigterm_dumps_octave_core\n\ +If this variable is set to a nonzero value and\n\ +@code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ +current variables the the file \"octave-core\" if it receives a\n\ +terminate signal. The default value is 1.\n\ +@end defvr"); + DEFCONST (SIG, make_sig_struct (), "-*- texinfo -*-\n\ @defvr {Built-in Variable} SIG\n\