Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
anbox
提交
579d2886
A
anbox
项目概览
openeuler
/
anbox
通知
24
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
anbox
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
579d2886
编写于
8月 22, 2017
作者:
S
Simon Fels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmds: apply proper daemonization handling for forked session manager
上级
07b32235
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
5 deletion
+42
-5
src/anbox/cmds/launch.cpp
src/anbox/cmds/launch.cpp
+42
-5
未找到文件。
src/anbox/cmds/launch.cpp
浏览文件 @
579d2886
...
...
@@ -38,6 +38,21 @@ namespace {
const
boost
::
posix_time
::
seconds
max_wait_timeout
{
240
};
const
int
max_restart_attempts
{
3
};
const
std
::
chrono
::
seconds
restart_interval
{
5
};
static
int
redirect_to_null
(
int
flags
,
int
fd
)
{
int
fd2
;
if
((
fd2
=
open
(
"/dev/null"
,
flags
))
<
0
)
return
-
1
;
if
(
fd2
==
fd
)
return
fd
;
if
(
dup2
(
fd2
,
fd
)
<
0
)
return
-
1
;
close
(
fd2
);
return
fd
;
}
}
bool
anbox
::
cmds
::
Launch
::
try_launch_activity
(
const
std
::
shared_ptr
<
dbus
::
stub
::
ApplicationManager
>
&
stub
)
{
...
...
@@ -144,12 +159,34 @@ anbox::cmds::Launch::Launch()
}
try
{
auto
flags
=
core
::
posix
::
StandardStream
::
stdout
|
core
::
posix
::
StandardStream
::
stderr
;
// If we have logging enable in debug mode then we allow the child process
// to print to stdout/stderr too.
if
(
Log
().
GetSeverity
()
==
Logger
::
Severity
::
kDebug
)
flags
=
core
::
posix
::
StandardStream
::
empty
;
auto
flags
=
core
::
posix
::
StandardStream
::
empty
;
auto
child
=
core
::
posix
::
fork
([
&
]()
{
// We redirect all in/out/err to /dev/null as they can't be seen
// anywhere. All logging output will directly go to syslog as we
// will become a session leader below which will get us rid of a
// controlling terminal.
if
(
redirect_to_null
(
O_RDONLY
,
0
)
<
0
||
redirect_to_null
(
O_WRONLY
,
1
)
<
0
||
redirect_to_null
(
O_WRONLY
,
2
)
<
0
)
{
ERROR
(
"Failed to redirect stdout/stderr/stdin: %s"
,
strerror
(
errno
));
return
core
::
posix
::
exit
::
Status
::
failure
;
}
// As we forked one time already we're sure that our process is
// not the session leader anymore so we can safely become the
// new one and lead the process group.
if
(
setsid
()
<
0
)
{
ERROR
(
"Failed to become new session leader: %s"
,
strerror
(
errno
));
return
core
::
posix
::
exit
::
Status
::
failure
;
}
umask
(
0077
);
if
(
chdir
(
"/"
)
<
0
)
{
ERROR
(
"Failed to change current directory: %s"
,
strerror
(
errno
));
return
core
::
posix
::
exit
::
Status
::
failure
;
}
auto
grandchild
=
core
::
posix
::
exec
(
exe_path
,
args
,
env
,
flags
);
grandchild
.
dont_kill_on_cleanup
();
return
core
::
posix
::
exit
::
Status
::
success
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录