add patch from MODAPP-86
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9653 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
f428a89f4c
commit
1c15146866
|
@ -1654,6 +1654,8 @@ SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
|
|||
SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string);
|
||||
SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string);
|
||||
|
||||
SWITCH_DECLARE(int) switch_system(char *cmd, switch_bool_t wait);
|
||||
|
||||
///\}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -346,6 +346,7 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
|
|||
|
||||
#define SWITCH_MAX_STACKS 32
|
||||
#define SWITCH_THREAD_STACKSIZE 240 * 1024
|
||||
#define SWITCH_SYSTEM_THREAD_STACKSIZE 8192 * 1024
|
||||
#define SWITCH_MAX_INTERVAL 120 /* we only do up to 120ms */
|
||||
#define SWITCH_INTERVAL_PAD 10 /* A little extra buffer space to be safe */
|
||||
#define SWITCH_MAX_SAMPLE_LEN 32
|
||||
|
|
|
@ -2518,7 +2518,7 @@ SWITCH_STANDARD_API(system_function)
|
|||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
|
||||
if (system(cmd) < 0) {
|
||||
if (switch_system(cmd, SWITCH_TRUE) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
|
||||
}
|
||||
stream->write_function(stream, "+OK\n");
|
||||
|
|
|
@ -1185,7 +1185,7 @@ SWITCH_STANDARD_APP(fax_detect_session_function)
|
|||
SWITCH_STANDARD_APP(system_session_function)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", data);
|
||||
if (system(data) < 0) {
|
||||
if (switch_system(data, SWITCH_TRUE) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
|
|||
|
||||
|
||||
static int os_execute (lua_State *L) {
|
||||
lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
|
||||
lua_pushinteger(L, switch_system(luaL_optstring(L, 1, NULL), SWITCH_TRUE));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3427,7 +3427,7 @@ static JSBool js_system(JSContext * cx, JSObject * obj, uintN argc, jsval * argv
|
|||
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
|
||||
|
||||
if (argc > 0 && (cmd = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
|
||||
*rval = INT_TO_JSVAL(system(cmd));
|
||||
*rval = INT_TO_JSVAL(switch_system(cmd, SWITCH_TRUE));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include <switch_private.h>
|
||||
#endif
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs = { 0 };
|
||||
|
||||
/* The main runtime obj we keep this hidden for ourselves */
|
||||
|
@ -1432,6 +1434,82 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void)
|
|||
switch_core_memory_reclaim();
|
||||
}
|
||||
|
||||
|
||||
struct system_thread_handle {
|
||||
const char * cmd;
|
||||
switch_thread_cond_t *cond;
|
||||
switch_mutex_t *mutex;
|
||||
switch_memory_pool_t *pool;
|
||||
int ret;
|
||||
};
|
||||
|
||||
static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj)
|
||||
{
|
||||
struct system_thread_handle *sth = (struct system_thread_handle *)obj;
|
||||
|
||||
/* struct rlimit rlim;
|
||||
|
||||
getrlimit(RLIMIT_STACK, &rlim);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "rlim_cur: %d rlim_max: %d\n", (int)rlim.rlim_cur, (int)rlim.rlim_max);
|
||||
*/
|
||||
|
||||
sth->ret = system(sth->cmd);
|
||||
|
||||
switch_mutex_lock(sth->mutex);
|
||||
switch_thread_cond_signal(sth->cond);
|
||||
switch_mutex_unlock(sth->mutex);
|
||||
|
||||
switch_core_destroy_memory_pool(&sth->pool);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_system(char *cmd, switch_bool_t wait)
|
||||
{
|
||||
switch_thread_t *thread;
|
||||
switch_threadattr_t *thd_attr;
|
||||
int ret = 0;
|
||||
struct system_thread_handle *sth;
|
||||
switch_memory_pool_t *pool;
|
||||
#ifndef __FreeBSD__
|
||||
struct rlimit rlim;
|
||||
|
||||
rlim.rlim_cur = SWITCH_SYSTEM_THREAD_STACKSIZE;
|
||||
rlim.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;;
|
||||
setrlimit(RLIMIT_STACK, &rlim);
|
||||
#endif
|
||||
|
||||
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(sth = switch_core_alloc(pool, sizeof(struct system_thread_handle)))) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sth->pool = pool;
|
||||
sth->cmd = switch_core_strdup(pool, cmd);
|
||||
|
||||
switch_thread_cond_create(&sth->cond, sth->pool);
|
||||
switch_mutex_init(&sth->mutex, SWITCH_MUTEX_NESTED, sth->pool);
|
||||
switch_mutex_lock(sth->mutex);
|
||||
|
||||
switch_threadattr_create(&thd_attr, sth->pool);
|
||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_SYSTEM_THREAD_STACKSIZE);
|
||||
// switch_threadattr_priority_increase(thd_attr);
|
||||
switch_thread_create(&thread, thd_attr, system_thread, sth, sth->pool);
|
||||
|
||||
if (wait) {
|
||||
switch_thread_cond_wait(sth->cond, sth->mutex);
|
||||
ret = sth->ret;
|
||||
}
|
||||
switch_mutex_unlock(sth->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
|
|
@ -479,7 +479,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
|
|||
#else
|
||||
switch_snprintf(buf, B64BUFFLEN, "/bin/cat %s | %s %s %s", filename, runtime.mailer_app, runtime.mailer_app_args, to);
|
||||
#endif
|
||||
if (system(buf)) {
|
||||
if (switch_system(buf, SWITCH_TRUE) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue