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
}
-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;
+
}
}
}
free(dcmd);
} else {
- switch_close_extra_files();
+ switch_close_extra_files(NULL, 0);
set_low_priority();
system(dcmd);
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);
}
+<<<<<<< HEAD
#ifndef WIN32
static int switch_stream_system_thread(const char *cmd, switch_stream_handle_t *stream)
{
}
#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
}
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);