]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
the threaded one seems to not work using only fork
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 20 Dec 2011 19:49:15 +0000 (13:49 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 20 Dec 2011 19:49:15 +0000 (13:49 -0600)
src/include/switch_core.h
src/switch_core.c
src/switch_xml.c

index 29c9cfc8c5eb93b4bbab8148233214be2a6704ae..b42e028ec0724f95bcdd28feec869475814e8bdc 100644 (file)
@@ -2304,7 +2304,7 @@ SWITCH_DECLARE(void) switch_say_file_handle_destroy(switch_say_file_handle_t **s
 SWITCH_DECLARE(switch_status_t) switch_say_file_handle_create(switch_say_file_handle_t **sh, const char *ext, switch_event_t **var_event);
 SWITCH_DECLARE(void) switch_say_file(switch_say_file_handle_t *sh, const char *fmt, ...);
 SWITCH_DECLARE(int) switch_max_file_desc(void);
-SWITCH_DECLARE(void) switch_close_extra_files(void);
+SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl);
 
 SWITCH_END_EXTERN_C
 #endif
index e69d49f7ade027a167e7fa01a855d50e2d519d41..d5d978b632c5309d3a7b56efdd4330fa35b8bf56 100644 (file)
@@ -2421,13 +2421,26 @@ SWITCH_DECLARE(int) switch_max_file_desc(void)
 
 }
 
-SWITCH_DECLARE(void) switch_close_extra_files(void)
+SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl)
 {
        int open_max = switch_max_file_desc();
-       int i;
+       int i, j;
 
        for (i = 3; i < open_max; i++) {
+               if (keep) {
+                       for (j = 0; j < keep_ttl; j++) {
+                               if (i == keep[j]) {
+                                       goto skip;
+                               }
+                       }
+               }
+
                close(i);
+
+       skip:
+
+               continue;
+
        }
 }
 
@@ -2456,7 +2469,7 @@ static int switch_system_fork(const char *cmd, switch_bool_t wait)
                }
                free(dcmd);
        } else {
-               switch_close_extra_files();
+               switch_close_extra_files(NULL, 0);
                
                set_low_priority();
                system(dcmd);
@@ -2508,7 +2521,7 @@ SWITCH_DECLARE(int) switch_stream_system_fork(const char *cmd, switch_stream_han
                        close(fds[0]);
                        waitpid(pid, NULL, 0);
                } else {                                /*  child */
-                       switch_close_extra_files();
+                       switch_close_extra_files(fds, 2);
                        close(fds[0]);
                        dup2(fds[1], STDOUT_FILENO);
                        switch_system(cmd, SWITCH_TRUE);
@@ -2525,6 +2538,7 @@ SWITCH_DECLARE(int) switch_stream_system_fork(const char *cmd, switch_stream_han
 
 }
 
+<<<<<<< HEAD
 #ifndef WIN32
 static int switch_stream_system_thread(const char *cmd, switch_stream_handle_t *stream)
 {
@@ -2584,17 +2598,15 @@ static int switch_stream_system_thread(const char *cmd, switch_stream_handle_t *
 }
 #endif
 
+=======
+>>>>>>> the threaded one seems to not work using only fork
 SWITCH_DECLARE(int) switch_stream_system(const char *cmd, switch_stream_handle_t *stream)
 {
 #ifdef WIN32
        stream->write_function(stream, "Capturing output not supported.\n");
        return switch_system(cmd, SWITCH_TRUE);
 #else
-       int (*sys_p)(const char *cmd, switch_stream_handle_t *stream);
-
-       sys_p = switch_test_flag((&runtime), SCF_THREADED_SYSTEM_EXEC) ? switch_stream_system_thread : switch_stream_system_fork;
-
-       return sys_p(cmd, stream);
+       return switch_stream_system_fork(cmd, stream);
 #endif
 
 }
index 2c57620210efba017202e3229ab4fd703ec42357..2c687839c8c2c44c2f85dbdb193a18f8aaca429a 100644 (file)
@@ -1256,7 +1256,7 @@ static int preprocess_exec(const char *cwd, const char *command, int write_fd, i
                        close(fds[0]);
                        waitpid(pid, NULL, 0);
                } else {                                /*  child */
-                       switch_close_extra_files();
+                       switch_close_extra_files(fds, 2);
                        close(fds[0]);
                        dup2(fds[1], STDOUT_FILENO);
                        switch_system(command, SWITCH_TRUE);