Merge branch 'master' into smgmaster

Conflicts:
	build/modules.conf.in
	libs/esl/fs_cli.c
This commit is contained in:
Moises Silva
2011-09-28 12:27:10 -04:00
406 changed files with 25830 additions and 41048 deletions
+184 -85
View File
@@ -81,6 +81,7 @@ static void send_heartbeat(void)
duration.ms, duration.ms == 1 ? "" : "s", duration.mms, duration.mms == 1 ? "" : "s");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Count", "%u", switch_core_session_count());
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Max-Sessions", "%u", switch_core_session_limit(0));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec", "%u", runtime.sps);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Since-Startup", "%" SWITCH_SIZE_T_FMT, switch_core_session_id() - 1);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Idle-CPU", "%f", switch_core_idle_cpu());
@@ -649,10 +650,48 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
switch_assert(SWITCH_GLOBAL_dirs.temp_dir);
}
static int32_t set_priority(void)
SWITCH_DECLARE(int32_t) set_low_priority(void)
{
#ifdef WIN32
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
#else
#ifdef USE_SCHED_SETSCHEDULER
/*
* Try to use a normal scheduler
*/
struct sched_param sched = { 0 };
sched.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
return -1;
}
#endif
#ifdef HAVE_SETPRIORITY
/*
* setpriority() works on FreeBSD (6.2), nice() doesn't
*/
if (setpriority(PRIO_PROCESS, getpid(), 19) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not set nice level\n");
return -1;
}
#else
if (nice(19) != 19) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not set nice level\n");
return -1;
}
#endif
#endif
return 0;
}
SWITCH_DECLARE(int32_t) set_realtime_priority(void)
{
#ifdef WIN32
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#else
#ifdef USE_SCHED_SETSCHEDULER
/*
@@ -687,46 +726,20 @@ static int32_t set_priority(void)
return 0;
}
SWITCH_DECLARE(int32_t) set_normal_priority(void)
{
return set_priority();
return 0;
}
SWITCH_DECLARE(int32_t) set_high_priority(void)
SWITCH_DECLARE(int32_t) set_auto_priority(void)
{
#ifdef WIN32
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#else
int pri;
#ifndef WIN32
runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
#ifdef USE_SETRLIMIT
struct rlimit lim = { RLIM_INFINITY, RLIM_INFINITY };
#endif
if ((pri = set_priority())) {
return pri;
/* If we have more than 1 cpu, we should use realtime priority so we can have priority threads */
if (runtime.cpu_count > 1) {
return set_realtime_priority();
}
#ifdef USE_SETRLIMIT
/*
* The amount of memory which can be mlocked is limited for non-root users.
* FS will segfault (= hitting the limit) soon after mlockall has been called
* and we've switched to a different user.
* So let's try to remove the mlock limit here...
*/
if (setrlimit(RLIMIT_MEMLOCK, &lim) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to disable memlock limit, application may crash if run as non-root user!\n");
}
#endif
#ifdef USE_MLOCKALL
/*
* Pin memory pages to RAM to prevent being swapped to disk
*/
mlockall(MCL_CURRENT | MCL_FUTURE);
#endif
#endif
return 0;
}
@@ -1253,6 +1266,9 @@ SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration)
duration = SWITCH_MIN_DTMF_DURATION;
}
runtime.max_dtmf_duration = duration;
if (duration < runtime.min_dtmf_duration) {
runtime.min_dtmf_duration = duration;
}
}
return runtime.max_dtmf_duration;
}
@@ -1267,6 +1283,15 @@ SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration)
duration = SWITCH_MAX_DTMF_DURATION;
}
runtime.default_dtmf_duration = duration;
if (duration < runtime.min_dtmf_duration) {
runtime.min_dtmf_duration = duration;
}
if (duration > runtime.max_dtmf_duration) {
runtime.max_dtmf_duration = duration;
}
}
return runtime.default_dtmf_duration;
}
@@ -1280,6 +1305,12 @@ SWITCH_DECLARE(uint32_t) switch_core_min_dtmf_duration(uint32_t duration)
if (duration > SWITCH_MAX_DTMF_DURATION) {
duration = SWITCH_MAX_DTMF_DURATION;
}
runtime.min_dtmf_duration = duration;
if (duration > runtime.max_dtmf_duration) {
runtime.max_dtmf_duration = duration;
}
}
return runtime.min_dtmf_duration;
}
@@ -1360,6 +1391,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
runtime.dummy_cng_frame.buflen = sizeof(runtime.dummy_data);
switch_set_flag((&runtime.dummy_cng_frame), SFF_CNG);
switch_set_flag((&runtime), SCF_AUTO_SCHEMAS);
switch_set_flag((&runtime), SCF_CLEAR_SQL);
switch_set_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
runtime.hard_log_level = SWITCH_LOG_DEBUG;
@@ -1370,6 +1403,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION;
runtime.odbc_dbtype = DBTYPE_DEFAULT;
runtime.dbname = NULL;
#ifndef WIN32
runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
#endif
/* INIT APR and Create the pool context */
if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
@@ -1487,38 +1523,20 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
}
#ifdef SIGQUIT
static void handle_SIGQUIT(int sig)
#ifndef WIN32
static void handle_SIGCHLD(int sig)
{
if (sig);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Sig Quit!\n");
return;
}
#endif
int status = 0;
int pid = 0;
#ifdef SIGPIPE
static void handle_SIGPIPE(int sig)
{
if (sig);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Sig Pipe!\n");
return;
}
#endif
#ifdef SIGPOLL
static void handle_SIGPOLL(int sig)
{
if (sig);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Sig Poll!\n");
return;
}
#endif
pid = wait(&status);
if (pid > 0) {
printf("ASS %d\n", pid);
}
#ifdef SIGIO
static void handle_SIGIO(int sig)
{
if (sig);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Sig I/O!\n");
return;
}
#endif
@@ -1680,6 +1698,12 @@ static void switch_load_core_config(const char *file)
} else {
switch_clear_flag((&runtime), SCF_AUTO_SCHEMAS);
}
} else if (!strcasecmp(var, "auto-clear-sql")) {
if (switch_true(val)) {
switch_set_flag((&runtime), SCF_CLEAR_SQL);
} else {
switch_clear_flag((&runtime), SCF_CLEAR_SQL);
}
} else if (!strcasecmp(var, "enable-early-hangup") && switch_true(val)) {
switch_set_flag((&runtime), SCF_EARLY_HANGUP);
} else if (!strcasecmp(var, "colorize-console") && switch_true(val)) {
@@ -1724,6 +1748,17 @@ static void switch_load_core_config(const char *file)
} else {
switch_clear_flag((&runtime), SCF_VERBOSE_EVENTS);
}
} else if (!strcasecmp(var, "threaded-system-exec") && !zstr(val)) {
#ifdef WIN32
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "threaded-system-exec is not implemented on this platform\n");
#else
int v = switch_true(val);
if (v) {
switch_set_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
} else {
switch_clear_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
}
#endif
} else if (!strcasecmp(var, "min-idle-cpu") && !zstr(val)) {
switch_core_min_idle_cpu(atof(val));
} else if (!strcasecmp(var, "tipping-point") && !zstr(val)) {
@@ -1917,17 +1952,24 @@ SWITCH_DECLARE(void) switch_core_set_signal_handlers(void)
{
/* set signal handlers */
signal(SIGINT, SIG_IGN);
#ifndef WIN32
if (switch_test_flag((&runtime), SCF_THREADED_SYSTEM_EXEC)) {
signal(SIGCHLD, SIG_DFL);
} else {
signal(SIGCHLD, handle_SIGCHLD);
}
#endif
#ifdef SIGPIPE
signal(SIGPIPE, handle_SIGPIPE);
signal(SIGPIPE, SIG_IGN);
#endif
#ifdef SIGQUIT
signal(SIGQUIT, handle_SIGQUIT);
signal(SIGQUIT, SIG_IGN);
#endif
#ifdef SIGPOLL
signal(SIGPOLL, handle_SIGPOLL);
signal(SIGPOLL, SIG_IGN);
#endif
#ifdef SIGIO
signal(SIGIO, handle_SIGIO);
signal(SIGIO, SIG_IGN);
#endif
#ifdef TRAP_BUS
signal(SIGBUS, handle_SIGBUS);
@@ -1970,6 +2012,18 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
newintval = switch_test_flag((&runtime), SCF_VERBOSE_EVENTS);
}
break;
case SCSC_THREADED_SYSTEM_EXEC:
if (intval) {
if (oldintval > -1) {
if (oldintval) {
switch_set_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
} else {
switch_clear_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
}
}
newintval = switch_test_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
}
break;
case SCSC_CALIBRATE_CLOCK:
switch_time_calibrate_clock();
break;
@@ -2237,24 +2291,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
return switch_test_flag((&runtime), SCF_RESTART) ? SWITCH_STATUS_RESTART : SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint)
{
switch_chat_interface_t *ci;
switch_status_t status;
if (!name || !(ci = switch_loadable_module_get_chat_interface(name)) || !ci->chat_send) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", name);
return SWITCH_STATUS_FALSE;
}
status = ci->chat_send(proto, from, to, subject, body, type, hint);
UNPROTECT_INTERFACE(ci);
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
{
const switch_management_interface_t *ptr;
@@ -2320,7 +2356,8 @@ static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj
return NULL;
}
SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
static int switch_system_thread(const char *cmd, switch_bool_t wait)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr;
@@ -2360,6 +2397,68 @@ SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
}
#ifdef WIN32
static int switch_system_fork(const char *cmd, switch_bool_t wait)
{
return switch_system_thread(cmd, wait);
}
#else
static int max_open(void)
{
int max;
#if defined(HAVE_GETDTABLESIZE)
max = getdtablesize();
#else
max = sysconf(_SC_OPEN_MAX);
#endif
return max;
}
static int switch_system_fork(const char *cmd, switch_bool_t wait)
{
int pid;
switch_core_set_signal_handlers();
pid = fork();
if (pid) {
if (wait) {
waitpid(pid, NULL, 0);
}
} else {
int open_max = max_open();
int i;
for (i = 3; i < open_max; i++) {
close(i);
}
set_low_priority();
i = system(cmd);
exit(0);
}
return 0;
}
#endif
SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
{
int (*sys_p)(const char *cmd, switch_bool_t wait);
sys_p = switch_test_flag((&runtime), SCF_THREADED_SYSTEM_EXEC) ? switch_system_thread : switch_system_fork;
return sys_p(cmd, wait);
}
/* For Emacs:
* Local Variables: