Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
ab847ff5
Commit
ab847ff5
authored
4 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善代码
parent
a3089f9a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
20 行删除
+19
-20
server/Process.cpp
+19
-20
没有找到文件。
server/Process.cpp
查看文件 @
ab847ff5
...
...
@@ -38,15 +38,14 @@ void Process::run(const string &cmd, const string &log_file_tmp) {
if
(
log_file_tmp
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"NUL"
;
}
else
{
}
else
{
log_file
=
StrPrinter
<<
log_file_tmp
<<
"."
<<
getCurrentMillisecond
();
}
//重定向shell日志至文件
auto
fp
=
File
::
create_file
(
log_file
.
data
(),
"ab"
);
if
(
!
fp
)
{
fprintf
(
stderr
,
"open log file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"open log file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
get_uv_error
(),
get_uv_errmsg
(
));
}
else
{
auto
log_fd
=
(
HANDLE
)(
_get_osfhandle
(
fileno
(
fp
)));
// dup to stdout and stderr.
...
...
@@ -65,15 +64,23 @@ void Process::run(const string &cmd, const string &log_file_tmp) {
_pid
=
pi
.
dwProcessId
;
_handle
=
pi
.
hProcess
;
fprintf
(
fp
,
"
\r\n\r\n
#### pid=%d,cmd=%s #####
\r\n\r\n
"
,
_pid
,
cmd
.
data
());
InfoL
<<
"start child proces "
<<
_pid
<<
", log file:"
<<
log_file
;
InfoL
<<
"start child proces
s
"
<<
_pid
<<
", log file:"
<<
log_file
;
}
else
{
WarnL
<<
"start child proces fail: "
<<
get_uv_errmsg
();
WarnL
<<
"start child proces
s
fail: "
<<
get_uv_errmsg
();
}
fclose
(
fp
);
#else
string
log_file
;
if
(
log_file_tmp
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"/dev/null"
;
}
else
{
log_file
=
StrPrinter
<<
log_file_tmp
<<
"."
<<
getpid
();
}
_pid
=
fork
();
if
(
_pid
<
0
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"fork child process fa
li
ed,err:"
<<
get_uv_errmsg
());
throw
std
::
runtime_error
(
StrPrinter
<<
"fork child process fa
il
ed,err:"
<<
get_uv_errmsg
());
}
if
(
_pid
==
0
)
{
//子进程关闭core文件生成
...
...
@@ -84,26 +91,18 @@ void Process::run(const string &cmd, const string &log_file_tmp) {
signal
(
SIGINT
,
SIG_IGN
);
signal
(
SIGTERM
,
SIG_IGN
);
string
log_file
;
if
(
log_file_tmp
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"/dev/null"
;
}
else
{
log_file
=
StrPrinter
<<
log_file_tmp
<<
"."
<<
getpid
();
}
//重定向shell日志至文件
auto
fp
=
File
::
create_file
(
log_file
.
data
(),
"ab"
);
if
(
!
fp
)
{
fprintf
(
stderr
,
"open log file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"open log file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
get_uv_error
(),
get_uv_errmsg
(
));
}
else
{
auto
log_fd
=
fileno
(
fp
);
// dup to stdout and stderr.
if
(
dup2
(
log_fd
,
STDOUT_FILENO
)
<
0
)
{
fprintf
(
stderr
,
"dup2 stdout file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"dup2 stdout file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
get_uv_error
(),
get_uv_errmsg
(
));
}
if
(
dup2
(
log_fd
,
STDERR_FILENO
)
<
0
)
{
fprintf
(
stderr
,
"dup2 stderr file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"dup2 stderr file %s failed:%d(%s)
\r\n
"
,
log_file
.
data
(),
get_uv_error
(),
get_uv_errmsg
(
));
}
// 关闭日志文件
::
fclose
(
fp
);
...
...
@@ -125,15 +124,15 @@ void Process::run(const string &cmd, const string &log_file_tmp) {
// EOF: NULL
charpv_params
[
params
.
size
()]
=
NULL
;
InfoL
<<
"start child proces "
<<
_pid
<<
", log file:"
<<
log_file
;
// TODO: execv or execvp
auto
ret
=
execv
(
params
[
0
].
c_str
(),
charpv_params
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"fork process failed
, errno=%d(%s)
\r\n
"
,
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"fork process failed
:%d(%s)
\r\n
"
,
get_uv_error
(),
get_uv_errmsg
(
));
}
exit
(
ret
);
}
InfoL
<<
"start child process "
<<
_pid
<<
", log file:"
<<
log_file
;
#endif // _WIN32
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论