Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-08-24 22:19:57 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6fe88d088c3cbcdc944f1dc6a76cca66a4c707fe
6fe88d08
1 parent
0e1861b0
for #367, process support redirect stdout and stderr.
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
89 行增加
和
19 行删除
trunk/src/app/srs_app_ffmpeg.cpp
trunk/src/app/srs_app_process.cpp
trunk/src/app/srs_app_process.hpp
trunk/src/app/srs_app_ffmpeg.cpp
查看文件 @
6fe88d0
...
...
@@ -24,12 +24,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_ffmpeg.hpp>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
// for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213
#ifndef _WIN32
#include <unistd.h>
#endif
#include <vector>
using
namespace
std
;
...
...
@@ -407,7 +411,7 @@ int SrsFFMPEG::start()
params
.
push_back
(
_output
);
// when specified the log file.
if
(
false
&&
!
log_file
.
empty
())
{
if
(
!
log_file
.
empty
())
{
// stdout
params
.
push_back
(
"1"
);
params
.
push_back
(
">"
);
...
...
trunk/src/app/srs_app_process.cpp
查看文件 @
6fe88d0
...
...
@@ -30,6 +30,11 @@
#include <signal.h>
#include <sys/types.h>
// for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213
#ifndef _WIN32
#include <unistd.h>
#endif
using
namespace
std
;
#include <srs_kernel_error.hpp>
...
...
@@ -57,8 +62,34 @@ int SrsProcess::initialize(string binary, vector<string> argv)
{
int
ret
=
ERROR_SUCCESS
;
bin
=
binary
;
params
=
argv
;
cli
=
bin
=
binary
;
for
(
int
i
=
0
;
i
<
(
int
)
argv
.
size
();
i
++
)
{
std
::
string
ffp
=
argv
[
i
];
cli
+=
" "
+
ffp
;
}
for
(
int
i
=
0
;
i
<
(
int
)
argv
.
size
();
i
++
)
{
std
::
string
ffp
=
argv
[
i
];
// remove the stdout and stderr.
if
(
ffp
==
"1"
)
{
if
(
i
+
2
<
(
int
)
argv
.
size
())
{
stdout_file
=
argv
[
i
+
2
];
i
+=
2
;
}
continue
;
}
else
if
(
ffp
==
"2"
)
{
if
(
i
+
2
<
(
int
)
argv
.
size
())
{
stderr_file
=
argv
[
i
+
2
];
i
+=
2
;
}
continue
;
}
// startup params.
params
.
push_back
(
ffp
);
}
return
ret
;
}
...
...
@@ -71,20 +102,12 @@ int SrsProcess::start()
return
ret
;
}
std
::
string
cli
;
if
(
true
)
{
for
(
int
i
=
0
;
i
<
(
int
)
params
.
size
();
i
++
)
{
std
::
string
ffp
=
params
[
i
];
cli
+=
ffp
;
if
(
i
<
(
int
)
params
.
size
()
-
1
)
{
cli
+=
" "
;
}
}
srs_trace
(
"fork process: %s %s"
,
bin
.
c_str
(),
cli
.
c_str
());
}
// generate the argv of process.
srs_trace
(
"fork process: %s"
,
cli
.
c_str
());
// for log
int
cid
=
_srs_context
->
get_id
();
int
ppid
=
getpid
();
// TODO: fork or vfork?
if
((
pid
=
fork
())
<
0
)
{
...
...
@@ -99,12 +122,51 @@ int SrsProcess::start()
signal
(
SIGINT
,
SIG_IGN
);
signal
(
SIGTERM
,
SIG_IGN
);
// redirect stdout to file.
if
(
!
stdout_file
.
empty
())
{
int
stdout_fd
=
-
1
;
int
flags
=
O_CREAT
|
O_WRONLY
|
O_APPEND
;
mode_t
mode
=
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
;
if
((
stdout_fd
=
::
open
(
stdout_file
.
c_str
(),
flags
,
mode
))
<
0
)
{
ret
=
ERROR_ENCODER_OPEN
;
fprintf
(
stderr
,
"open process stdout %s failed. ret=%d"
,
stdout_file
.
c_str
(),
ret
);
return
ret
;
}
if
(
dup2
(
stdout_fd
,
STDOUT_FILENO
)
<
0
)
{
ret
=
ERROR_ENCODER_DUP2
;
srs_error
(
"dup2 process stdout failed. ret=%d"
,
ret
);
return
ret
;
}
}
// redirect stderr to file.
if
(
!
stderr_file
.
empty
())
{
int
stderr_fd
=
-
1
;
int
flags
=
O_CREAT
|
O_WRONLY
|
O_APPEND
;
mode_t
mode
=
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
;
if
((
stderr_fd
=
::
open
(
stderr_file
.
c_str
(),
flags
,
mode
))
<
0
)
{
ret
=
ERROR_ENCODER_OPEN
;
fprintf
(
stderr
,
"open process stderr %s failed. ret=%d"
,
stderr_file
.
c_str
(),
ret
);
return
ret
;
}
if
(
dup2
(
stderr_fd
,
STDERR_FILENO
)
<
0
)
{
ret
=
ERROR_ENCODER_DUP2
;
srs_error
(
"dup2 process stderr failed. ret=%d"
,
ret
);
return
ret
;
}
}
// log basic info
if
(
true
)
{
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"process parent cid=%d"
,
cid
);
fprintf
(
stderr
,
"process binary=%s"
,
bin
.
c_str
());
fprintf
(
stderr
,
"process params: %s %s"
,
bin
.
c_str
(),
cli
.
c_str
());
fprintf
(
stderr
,
"process parent pid=%d
\n
"
,
ppid
);
fprintf
(
stderr
,
"process parent cid=%d
\n
"
,
cid
);
fprintf
(
stderr
,
"process binary=%s
\n
"
,
bin
.
c_str
());
fprintf
(
stderr
,
"process cli: %s
\n
"
,
cli
.
c_str
());
}
// close other fds
...
...
@@ -133,7 +195,7 @@ int SrsProcess::start()
// parent.
if
(
pid
>
0
)
{
is_started
=
true
;
srs_trace
(
"vfored process, pid=%d,
cli
=%s"
,
pid
,
bin
.
c_str
());
srs_trace
(
"vfored process, pid=%d,
bin
=%s"
,
pid
,
bin
.
c_str
());
return
ret
;
}
...
...
trunk/src/app/srs_app_process.hpp
查看文件 @
6fe88d0
...
...
@@ -51,7 +51,11 @@ private:
pid_t
pid
;
private
:
std
::
string
bin
;
std
::
string
stdout_file
;
std
::
string
stderr_file
;
std
::
vector
<
std
::
string
>
params
;
// the cli to fork process.
std
::
string
cli
;
public
:
SrsProcess
();
virtual
~
SrsProcess
();
...
...
请
注册
或
登录
后发表评论