From f4a50a5e916e905abc43a09aa7fdeb0dbcd16389 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jan 2010 21:00:32 +0000 Subject: [PATCH] save history when stoping now git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16312 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_console.h | 1 + src/include/switch_types.h | 4 +++- src/mod/applications/mod_commands/mod_commands.c | 7 +++++++ src/switch_console.c | 9 +++++++++ src/switch_core.c | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/include/switch_console.h b/src/include/switch_console.h index e31600defb..022441d258 100644 --- a/src/include/switch_console.h +++ b/src/include/switch_console.h @@ -88,6 +88,7 @@ SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word, FILE *console_out, switch_stream_handle_t *stream, switch_xml_t xml); SWITCH_DECLARE(void) switch_console_sort_matches(switch_console_callback_match_t *matches); +SWITCH_DECLARE(void) switch_console_save_history(void); SWITCH_END_EXTERN_C #endif diff --git a/src/include/switch_types.h b/src/include/switch_types.h index b0e73eae10..d664aa8030 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1437,7 +1437,9 @@ typedef enum { SCSC_DEBUG_LEVEL, SCSC_FLUSH_DB_HANDLES, SCSC_SHUTDOWN_NOW, - SCSC_CALIBRATE_CLOCK + SCSC_CALIBRATE_CLOCK, + SCSC_SAVE_HISTORY, + SCSC_CRASH } switch_session_ctl_t; typedef enum { diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 085c5cfe10..7ad64f393d 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1472,6 +1472,13 @@ SWITCH_STANDARD_API(ctl_function) stream->write_function(stream, "+OK\n"); } else if (!strcasecmp(argv[0], "calibrate_clock")) { switch_core_session_ctl(SCSC_CALIBRATE_CLOCK, NULL); + stream->write_function(stream, "+OK\n"); + } else if (!strcasecmp(argv[0], "crash")) { + switch_core_session_ctl(SCSC_CRASH, NULL); + stream->write_function(stream, "+OK\n"); + } else if (!strcasecmp(argv[0], "save_history")) { + switch_core_session_ctl(SCSC_SAVE_HISTORY, NULL); + stream->write_function(stream, "+OK\n"); } else if (!strcasecmp(argv[0], "shutdown")) { switch_session_ctl_t command = SCSC_SHUTDOWN; int x = 0; diff --git a/src/switch_console.c b/src/switch_console.c index b69d9908ac..1121a4aaed 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -842,6 +842,15 @@ static unsigned char console_fnkey_pressed(int i) return CC_REDISPLAY; } +SWITCH_DECLARE(void) switch_console_save_history(void) +{ +#ifdef SWITCH_HAVE_LIBEDIT + history(myhistory, &ev, H_SAVE, hfile); +#else + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "NOT IMPLEMENTED!\n"); +#endif +} + #ifdef SWITCH_HAVE_LIBEDIT static char prompt_str[512] = ""; diff --git a/src/switch_core.c b/src/switch_core.c index f0e6bd113c..4dab164909 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1633,7 +1633,16 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_ case SCSC_CANCEL_SHUTDOWN: switch_clear_flag((&runtime), SCF_SHUTDOWN_REQUESTED); break; + case SCSC_SAVE_HISTORY: + switch_console_save_history(); + break; + case SCSC_CRASH: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Declinatio Mortuus Obfirmo!\n"); + switch_console_save_history(); + abort(); + break; case SCSC_SHUTDOWN_NOW: + switch_console_save_history(); exit(0); break; case SCSC_SHUTDOWN_ELEGANT: