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
This commit is contained in:
Michael Jerris 2007-03-30 02:20:13 +00:00
parent 92d726b995
commit d292e9de4f
6 changed files with 74 additions and 71 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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));

View File

@ -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 <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#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;

View File

@ -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);

View File

@ -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 <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#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;