Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
d7a37e97
提交
d7a37e97
authored
12月 20, 2011
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow system API command to capture output from the executed command
上级
0a8e6129
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
154 行增加
和
21 行删除
+154
-21
switch_core.h
src/include/switch_core.h
+3
-1
mod_commands.c
src/mod/applications/mod_commands/mod_commands.c
+2
-3
switch_core.c
src/switch_core.c
+148
-17
switch_xml.c
src/switch_xml.c
+1
-0
没有找到文件。
src/include/switch_core.h
浏览文件 @
d7a37e97
...
@@ -2115,6 +2115,7 @@ SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
...
@@ -2115,6 +2115,7 @@ 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_complete
(
const
char
*
string
);
SWITCH_DECLARE
(
switch_status_t
)
switch_console_set_alias
(
const
char
*
string
);
SWITCH_DECLARE
(
switch_status_t
)
switch_console_set_alias
(
const
char
*
string
);
SWITCH_DECLARE
(
int
)
switch_system
(
const
char
*
cmd
,
switch_bool_t
wait
);
SWITCH_DECLARE
(
int
)
switch_system
(
const
char
*
cmd
,
switch_bool_t
wait
);
SWITCH_DECLARE
(
int
)
switch_stream_system
(
const
char
*
cmd
,
switch_stream_handle_t
*
stream
);
SWITCH_DECLARE
(
void
)
switch_cond_yield
(
switch_interval_time_t
t
);
SWITCH_DECLARE
(
void
)
switch_cond_yield
(
switch_interval_time_t
t
);
SWITCH_DECLARE
(
void
)
switch_cond_next
(
void
);
SWITCH_DECLARE
(
void
)
switch_cond_next
(
void
);
SWITCH_DECLARE
(
switch_status_t
)
switch_core_chat_send_args
(
const
char
*
dest_proto
,
const
char
*
proto
,
const
char
*
from
,
const
char
*
to
,
SWITCH_DECLARE
(
switch_status_t
)
switch_core_chat_send_args
(
const
char
*
dest_proto
,
const
char
*
proto
,
const
char
*
from
,
const
char
*
to
,
...
@@ -2302,7 +2303,8 @@ SWITCH_DECLARE(char *) switch_say_file_handle_detach_path(switch_say_file_handle
...
@@ -2302,7 +2303,8 @@ SWITCH_DECLARE(char *) switch_say_file_handle_detach_path(switch_say_file_handle
SWITCH_DECLARE
(
void
)
switch_say_file_handle_destroy
(
switch_say_file_handle_t
**
sh
);
SWITCH_DECLARE
(
void
)
switch_say_file_handle_destroy
(
switch_say_file_handle_t
**
sh
);
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
(
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
(
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_END_EXTERN_C
SWITCH_END_EXTERN_C
#endif
#endif
...
...
src/mod/applications/mod_commands/mod_commands.c
浏览文件 @
d7a37e97
...
@@ -4791,11 +4791,10 @@ SWITCH_STANDARD_API(system_function)
...
@@ -4791,11 +4791,10 @@ SWITCH_STANDARD_API(system_function)
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_NOTICE
,
"Executing command: %s
\n
"
,
cmd
);
if
(
switch_stream_system
(
cmd
,
stream
)
<
0
)
{
if
(
switch_system
(
cmd
,
SWITCH_TRUE
)
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_NOTICE
,
"Failed to execute command: %s
\n
"
,
cmd
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_NOTICE
,
"Failed to execute command: %s
\n
"
,
cmd
);
}
}
stream
->
write_function
(
stream
,
"+OK
\n
"
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
...
src/switch_core.c
浏览文件 @
d7a37e97
...
@@ -2321,6 +2321,7 @@ struct system_thread_handle {
...
@@ -2321,6 +2321,7 @@ struct system_thread_handle {
switch_mutex_t
*
mutex
;
switch_mutex_t
*
mutex
;
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
int
ret
;
int
ret
;
int
*
fds
;
};
};
static
void
*
SWITCH_THREAD_FUNC
system_thread
(
switch_thread_t
*
thread
,
void
*
obj
)
static
void
*
SWITCH_THREAD_FUNC
system_thread
(
switch_thread_t
*
thread
,
void
*
obj
)
...
@@ -2339,6 +2340,10 @@ static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj
...
@@ -2339,6 +2340,10 @@ static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj
#endif
#endif
#endif
#endif
if
(
sth
->
fds
)
{
dup2
(
sth
->
fds
[
1
],
STDOUT_FILENO
);
}
sth
->
ret
=
system
(
sth
->
cmd
);
sth
->
ret
=
system
(
sth
->
cmd
);
#if 0
#if 0
...
@@ -2400,28 +2405,42 @@ static int switch_system_thread(const char *cmd, switch_bool_t wait)
...
@@ -2400,28 +2405,42 @@ static int switch_system_thread(const char *cmd, switch_bool_t wait)
return
ret
;
return
ret
;
}
}
SWITCH_DECLARE
(
int
)
switch_max_file_desc
(
void
)
#ifdef WIN32
static
int
switch_system_fork
(
const
char
*
cmd
,
switch_bool_t
wait
)
{
{
return
switch_system_thread
(
cmd
,
wait
);
int
max
=
0
;
}
#else
static
int
max_open
(
void
)
{
int
max
;
#ifndef WIN32
#if defined(HAVE_GETDTABLESIZE)
#if defined(HAVE_GETDTABLESIZE)
max
=
getdtablesize
();
max
=
getdtablesize
();
#else
#else
max
=
sysconf
(
_SC_OPEN_MAX
);
max
=
sysconf
(
_SC_OPEN_MAX
);
#endif
#endif
#endif
return
max
;
return
max
;
}
}
SWITCH_DECLARE
(
void
)
switch_close_extra_files
(
void
)
{
int
open_max
=
switch_max_file_desc
();
int
i
;
for
(
i
=
3
;
i
<
open_max
;
i
++
)
{
close
(
i
);
}
}
#ifdef WIN32
static
int
switch_system_fork
(
const
char
*
cmd
,
switch_bool_t
wait
)
{
return
switch_system_thread
(
cmd
,
wait
);
}
#else
static
int
switch_system_fork
(
const
char
*
cmd
,
switch_bool_t
wait
)
static
int
switch_system_fork
(
const
char
*
cmd
,
switch_bool_t
wait
)
{
{
int
pid
;
int
pid
;
...
@@ -2437,15 +2456,10 @@ static int switch_system_fork(const char *cmd, switch_bool_t wait)
...
@@ -2437,15 +2456,10 @@ static int switch_system_fork(const char *cmd, switch_bool_t wait)
}
}
free
(
dcmd
);
free
(
dcmd
);
}
else
{
}
else
{
int
open_max
=
max_open
();
switch_close_extra_files
();
int
i
;
for
(
i
=
3
;
i
<
open_max
;
i
++
)
{
close
(
i
);
}
set_low_priority
();
set_low_priority
();
i
=
system
(
dcmd
);
system
(
dcmd
);
free
(
dcmd
);
free
(
dcmd
);
exit
(
0
);
exit
(
0
);
}
}
...
@@ -2467,6 +2481,123 @@ SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
...
@@ -2467,6 +2481,123 @@ SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
}
}
SWITCH_DECLARE
(
int
)
switch_stream_system_fork
(
const
char
*
cmd
,
switch_stream_handle_t
*
stream
)
{
#ifdef WIN32
return
switch_system
(
cmd
,
SWITCH_TRUE
);
#else
int
fds
[
2
],
pid
=
0
;
if
(
pipe
(
fds
))
{
goto
end
;
}
else
{
/* good to go */
pid
=
fork
();
if
(
pid
<
0
)
{
/* ok maybe not */
close
(
fds
[
0
]);
close
(
fds
[
1
]);
goto
end
;
}
else
if
(
pid
)
{
/* parent */
char
buf
[
1024
]
=
""
;
int
bytes
;
close
(
fds
[
1
]);
while
((
bytes
=
read
(
fds
[
0
],
buf
,
sizeof
(
buf
)))
>
0
)
{
stream
->
raw_write_function
(
stream
,
(
unsigned
char
*
)
buf
,
bytes
);
}
close
(
fds
[
0
]);
waitpid
(
pid
,
NULL
,
0
);
}
else
{
/* child */
switch_close_extra_files
();
close
(
fds
[
0
]);
dup2
(
fds
[
1
],
STDOUT_FILENO
);
switch_system
(
cmd
,
SWITCH_TRUE
);
close
(
fds
[
1
]);
exit
(
0
);
}
}
end
:
return
0
;
#endif
}
static
int
switch_stream_system_thread
(
const
char
*
cmd
,
switch_stream_handle_t
*
stream
)
{
#ifdef WIN32
return
switch_system
(
cmd
,
SWITCH_TRUE
);
#else
switch_thread_t
*
thread
;
switch_threadattr_t
*
thd_attr
;
int
ret
=
0
;
struct
system_thread_handle
*
sth
;
switch_memory_pool_t
*
pool
;
int
fds
[
2
]
=
{
0
};
char
buf
[
1024
]
=
""
;
int
bytes
;
if
(
pipe
(
fds
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Pipe Failure
\n
"
);
return
1
;
}
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
);
sth
->
fds
=
fds
;
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_detach_set
(
thd_attr
,
1
);
switch_thread_create
(
&
thread
,
thd_attr
,
system_thread
,
sth
,
sth
->
pool
);
close
(
fds
[
1
]);
while
((
bytes
=
read
(
fds
[
0
],
buf
,
sizeof
(
buf
)))
>
0
)
{
stream
->
raw_write_function
(
stream
,
(
unsigned
char
*
)
buf
,
bytes
);
}
close
(
fds
[
0
]);
switch_thread_cond_wait
(
sth
->
cond
,
sth
->
mutex
);
ret
=
sth
->
ret
;
switch_mutex_unlock
(
sth
->
mutex
);
return
ret
;
#endif
}
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
);
#endif
}
/* For Emacs:
/* For Emacs:
* Local Variables:
* Local Variables:
* mode:c
* mode:c
...
...
src/switch_xml.c
浏览文件 @
d7a37e97
...
@@ -1256,6 +1256,7 @@ static int preprocess_exec(const char *cwd, const char *command, int write_fd, i
...
@@ -1256,6 +1256,7 @@ static int preprocess_exec(const char *cwd, const char *command, int write_fd, i
close
(
fds
[
0
]);
close
(
fds
[
0
]);
waitpid
(
pid
,
NULL
,
0
);
waitpid
(
pid
,
NULL
,
0
);
}
else
{
/* child */
}
else
{
/* child */
switch_close_extra_files
();
close
(
fds
[
0
]);
close
(
fds
[
0
]);
dup2
(
fds
[
1
],
STDOUT_FILENO
);
dup2
(
fds
[
1
],
STDOUT_FILENO
);
switch_system
(
command
,
SWITCH_TRUE
);
switch_system
(
command
,
SWITCH_TRUE
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论