[Freeswitch-svn] [commit] r9653 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/applications/mod_dptools mod/languages/mod_lua/lua mod/languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Fri Sep 26 11:50:13 EDT 2008


Author: anthm
Date: Fri Sep 26 11:50:12 2008
New Revision: 9653

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/languages/mod_lua/lua/loslib.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_utils.c

Log:
add patch from MODAPP-86

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Fri Sep 26 11:50:12 2008
@@ -1654,6 +1654,8 @@
 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);
+
 ///\}
 
 /*!

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Fri Sep 26 11:50:12 2008
@@ -346,6 +346,7 @@
 
 #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

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Fri Sep 26 11:50:12 2008
@@ -2518,7 +2518,7 @@
     } 
 
     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");

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Fri Sep 26 11:50:12 2008
@@ -1185,7 +1185,7 @@
 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);
 	}
 }

Modified: freeswitch/trunk/src/mod/languages/mod_lua/lua/loslib.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/lua/loslib.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/lua/loslib.c	Fri Sep 26 11:50:12 2008
@@ -36,7 +36,7 @@
 
 
 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;
 }
 

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Fri Sep 26 11:50:12 2008
@@ -3427,7 +3427,7 @@
 	*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;
 	}
 

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Fri Sep 26 11:50:12 2008
@@ -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_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

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Fri Sep 26 11:50:12 2008
@@ -479,7 +479,7 @@
 #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);
 	}
 



More information about the Freeswitch-svn mailing list