From d292e9de4f7b9702d2b460aa287d46a63b3d8372 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 30 Mar 2007 02:20:13 +0000 Subject: [PATCH] don't export our private functions. fix crash protection build. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4803 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/private/switch_core.h | 9 +++-- src/switch_core.c | 14 ++----- src/switch_core_memory.c | 2 +- src/switch_core_session.c | 52 +------------------------ src/switch_core_sqldb.c | 4 +- src/switch_core_state_machine.c | 64 ++++++++++++++++++++++++++++++- 6 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/include/private/switch_core.h b/src/include/private/switch_core.h index 90a4a344aa..11ea9cb025 100644 --- a/src/include/private/switch_core.h +++ b/src/include/private/switch_core.h @@ -143,7 +143,8 @@ struct switch_media_bug { struct switch_media_bug *next; }; -SWITCH_DECLARE(void) switch_core_sqldb_start(switch_memory_pool_t *pool); -SWITCH_DECLARE(void) switch_core_sqldb_stop(void); -SWITCH_DECLARE(void) switch_core_session_init(switch_memory_pool_t *pool); -SWITCH_DECLARE(switch_memory_pool_t *) switch_core_memory_init(void); +void switch_core_sqldb_start(switch_memory_pool_t *pool); +void switch_core_sqldb_stop(void); +void switch_core_session_init(switch_memory_pool_t *pool); +void switch_core_state_machine_init(switch_memory_pool_t *pool); +switch_memory_pool_t *switch_core_memory_init(void); diff --git a/src/switch_core.c b/src/switch_core.c index 5ee66c3c50..7d5eeddc19 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -43,9 +43,6 @@ static struct { switch_time_t initiated; switch_hash_t *global_vars; switch_memory_pool_t *memory_pool; -#ifdef CRASH_PROT - switch_hash_t *stack_table; -#endif const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS]; int state_handler_index; FILE *console; @@ -426,8 +423,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err switch_core_set_globals(); switch_core_session_init(runtime.memory_pool); + switch_core_state_machine_init(runtime.memory_pool); switch_core_hash_init(&runtime.global_vars, runtime.memory_pool); + + if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) { apr_terminate(); return SWITCH_STATUS_MEMERR; @@ -486,12 +486,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err switch_rtp_init(runtime.memory_pool); runtime.running = 1; - -#ifdef CRASH_PROT - switch_core_hash_init(&runtime.stack_table, runtime.memory_pool); -#endif - - switch_scheduler_task_thread_start(); runtime.initiated = switch_time_now(); @@ -673,8 +667,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) runtime.console = NULL; } - switch_yield(1000000); - switch_safe_free(SWITCH_GLOBAL_dirs.base_dir); switch_safe_free(SWITCH_GLOBAL_dirs.mod_dir); switch_safe_free(SWITCH_GLOBAL_dirs.conf_dir); diff --git a/src/switch_core_memory.c b/src/switch_core_memory.c index a773a15044..32b2ef849b 100644 --- a/src/switch_core_memory.c +++ b/src/switch_core_memory.c @@ -212,7 +212,7 @@ SWITCH_DECLARE(void *) switch_core_alloc(switch_memory_pool_t *pool, switch_size return ptr; } -SWITCH_DECLARE(switch_memory_pool_t *) switch_core_memory_init(void) +switch_memory_pool_t *switch_core_memory_init(void) { memset(&runtime, 0, sizeof(runtime)); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 88a8aeb765..5e5962592e 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -638,56 +638,6 @@ SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t * return session->thread_running; } -#ifdef CRASH_PROT -#if defined (__GNUC__) && defined (LINUX) -#include -#include -#include -#define STACK_LEN 10 - -/* Obtain a backtrace and print it to stdout. */ -static void print_trace(void) -{ - void *array[STACK_LEN]; - size_t size; - char **strings; - size_t i; - - size = backtrace(array, STACK_LEN); - strings = backtrace_symbols(array, size); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CRIT, "%s\n", strings[i]); - } - - free(strings); -} -#else -static void print_trace(void) -{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Trace not avaliable =(\n"); -} -#endif - - -static void handle_fatality(int sig) -{ - switch_thread_id_t thread_id; - jmp_buf *env; - - if (sig && (thread_id = switch_thread_self()) - && (env = (jmp_buf *) apr_hash_get(runtime.stack_table, &thread_id, sizeof(thread_id)))) { - print_trace(); - longjmp(*env, sig); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Caught signal %d for unmapped thread!", sig); - abort(); - } -} -#endif - SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session) { @@ -900,7 +850,7 @@ SWITCH_DECLARE(uint32_t) switch_core_session_limit(uint32_t new_limit) } -SWITCH_DECLARE(void) switch_core_session_init(switch_memory_pool_t *pool) +void switch_core_session_init(switch_memory_pool_t *pool) { memset(&runtime, 0, sizeof(runtime)); runtime.session_limit = 1000; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index e3b154e839..1313048a2a 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -340,7 +340,7 @@ static void core_event_handler(switch_event_t *event) } -SWITCH_DECLARE(void) switch_core_sqldb_start(switch_memory_pool_t *pool) +void switch_core_sqldb_start(switch_memory_pool_t *pool) { switch_thread_t *thread; switch_threadattr_t *thd_attr;; @@ -405,7 +405,7 @@ SWITCH_DECLARE(void) switch_core_sqldb_start(switch_memory_pool_t *pool) } -SWITCH_DECLARE(void) switch_core_sqldb_stop(void) +void switch_core_sqldb_stop(void) { switch_queue_push(runtime.sql_queue, NULL); diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 3d9452fb36..363899a451 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -213,6 +213,66 @@ static void switch_core_standard_on_hibernate(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard HIBERNATE\n"); } + +#ifdef CRASH_PROT +static switch_hash_t *stack_table; +#if defined (__GNUC__) && defined (LINUX) +#include +#include +#include +#define STACK_LEN 10 + +/* Obtain a backtrace and print it to stdout. */ +static void print_trace(void) +{ + void *array[STACK_LEN]; + size_t size; + char **strings; + size_t i; + + size = backtrace(array, STACK_LEN); + strings = backtrace_symbols(array, size); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++) { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CRIT, "%s\n", strings[i]); + } + + free(strings); +} +#else +static void print_trace(void) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Trace not avaliable =(\n"); +} +#endif + + +static void handle_fatality(int sig) +{ + switch_thread_id_t thread_id; + jmp_buf *env; + + if (sig && (thread_id = switch_thread_self()) + && (env = (jmp_buf *) apr_hash_get(stack_table, &thread_id, sizeof(thread_id)))) { + print_trace(); + longjmp(*env, sig); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Caught signal %d for unmapped thread!", sig); + abort(); + } +} +#endif + +void switch_core_state_machine_init(switch_memory_pool_t *pool) +{ + (void)0; +#ifdef CRASH_PROT + switch_core_hash_init(&stack_table, pool); +#endif +} + SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) { switch_channel_state_t state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE, endstate; @@ -241,7 +301,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Thread has crashed for channel %s\n", switch_channel_get_name(session->channel)); switch_channel_hangup(session->channel, SWITCH_CAUSE_CRASH); } else { - apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), &env); + apr_hash_set(stack_table, &thread_id, sizeof(thread_id), &env); } #endif /* @@ -596,7 +656,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) switch_mutex_unlock(session->mutex); #ifdef CRASH_PROT - apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL); + apr_hash_set(stack_table, &thread_id, sizeof(thread_id), NULL); #endif session->thread_running = 0;