Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
anbox
提交
e1aff472
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,发现更多精彩内容 >>
提交
e1aff472
编写于
1月 31, 2017
作者:
S
Simon Fels
提交者:
GitHub
1月 31, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35 from morphis/feature/refactor-config
Refactor configuration to be more dynamic
上级
32478856
fb6277f9
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
81 addition
and
110 deletion
+81
-110
src/anbox/audio/server.cpp
src/anbox/audio/server.cpp
+1
-1
src/anbox/cmds/run.cpp
src/anbox/cmds/run.cpp
+9
-8
src/anbox/config.cpp
src/anbox/config.cpp
+25
-60
src/anbox/config.h
src/anbox/config.h
+24
-12
src/anbox/container/client.cpp
src/anbox/container/client.cpp
+1
-1
src/anbox/container/lxc_container.cpp
src/anbox/container/lxc_container.cpp
+16
-21
src/anbox/container/service.cpp
src/anbox/container/service.cpp
+3
-4
src/anbox/input/manager.cpp
src/anbox/input/manager.cpp
+2
-3
未找到文件。
src/anbox/audio/server.cpp
浏览文件 @
e1aff472
...
...
@@ -49,7 +49,7 @@ namespace anbox {
namespace
audio
{
Server
::
Server
(
const
std
::
shared_ptr
<
Runtime
>&
rt
,
const
std
::
shared_ptr
<
platform
::
Policy
>
&
platform_policy
)
:
platform_policy_
(
platform_policy
),
socket_file_
(
utils
::
string_format
(
"%s/anbox_audio"
,
config
::
socket_path
())),
socket_file_
(
utils
::
string_format
(
"%s/anbox_audio"
,
SystemConfiguration
::
instance
().
socket_dir
())),
connector_
(
std
::
make_shared
<
network
::
PublishedSocketConnector
>
(
socket_file_
,
rt
,
std
::
make_shared
<
network
::
DelegateConnectionCreator
<
boost
::
asio
::
local
::
stream_protocol
>>
(
std
::
bind
(
&
Server
::
create_connection_for
,
this
,
_1
)))),
...
...
src/anbox/cmds/run.cpp
浏览文件 @
e1aff472
...
...
@@ -94,7 +94,8 @@ anbox::cmds::Run::Run(const BusFactory &bus_factory)
});
utils
::
ensure_paths
({
config
::
socket_path
(),
config
::
host_input_device_path
(),
SystemConfiguration
::
instance
().
socket_dir
(),
SystemConfiguration
::
instance
().
input_device_dir
(),
});
auto
rt
=
Runtime
::
create
();
...
...
@@ -128,15 +129,17 @@ anbox::cmds::Run::Run(const BusFactory &bus_factory)
auto
audio_server
=
std
::
make_shared
<
audio
::
Server
>
(
rt
,
policy
);
const
auto
socket_path
=
SystemConfiguration
::
instance
().
socket_dir
();
// The qemu pipe is used as a very fast communication channel between guest
// and host for things like the GLES emulation/translation, the RIL or ADB.
auto
qemu_pipe_connector
=
std
::
make_shared
<
network
::
PublishedSocketConnector
>
(
utils
::
string_format
(
"%s/qemu_pipe"
,
config
::
socket_path
()
),
rt
,
utils
::
string_format
(
"%s/qemu_pipe"
,
socket_path
),
rt
,
std
::
make_shared
<
qemu
::
PipeConnectionCreator
>
(
gl_server
->
renderer
(),
rt
));
auto
bridge_connector
=
std
::
make_shared
<
network
::
PublishedSocketConnector
>
(
utils
::
string_format
(
"%s/anbox_bridge"
,
config
::
socket_path
()
),
rt
,
utils
::
string_format
(
"%s/anbox_bridge"
,
socket_path
),
rt
,
std
::
make_shared
<
rpc
::
ConnectionCreator
>
(
rt
,
[
&
](
const
std
::
shared_ptr
<
network
::
MessageSender
>
&
sender
)
{
auto
pending_calls
=
std
::
make_shared
<
rpc
::
PendingCallCache
>
();
...
...
@@ -161,20 +164,18 @@ anbox::cmds::Run::Run(const BusFactory &bus_factory)
{
qemu_pipe_connector
->
socket_file
(),
"/dev/qemu_pipe"
},
{
bridge_connector
->
socket_file
(),
"/dev/anbox_bridge"
},
{
audio_server
->
socket_file
(),
"/dev/anbox_audio"
},
{
config
::
host_input_device_path
(),
"/dev/input"
},
{
SystemConfiguration
::
instance
().
input_device_dir
(),
"/dev/input"
},
{
"/dev/binder"
,
"/dev/binder"
},
{
"/dev/ashmem"
,
"/dev/ashmem"
},
{
"/dev/fuse"
,
"/dev/fuse"
},
};
dispatcher
->
dispatch
(
[
&
]()
{
container
.
start_container
(
container_configuration
);
});
dispatcher
->
dispatch
([
&
]()
{
container
.
start_container
(
container_configuration
);
});
auto
bus
=
bus_factory_
();
bus
->
install_executor
(
core
::
dbus
::
asio
::
make_executor
(
bus
,
rt
->
service
()));
auto
skeleton
=
anbox
::
dbus
::
skeleton
::
Service
::
create_for_bus
(
bus
,
android_api_stub
);
auto
skeleton
=
anbox
::
dbus
::
skeleton
::
Service
::
create_for_bus
(
bus
,
android_api_stub
);
rt
->
start
();
trap
->
run
();
...
...
src/anbox/config.cpp
浏览文件 @
e1aff472
...
...
@@ -15,93 +15,58 @@
*
*/
#include <cstring>
#include "anbox/config.h"
#include "anbox/utils.h"
#include <boost/filesystem.hpp>
namespace
fs
=
boost
::
filesystem
;
namespace
anbox
{
namespace
config
{
std
::
string
in_snap_dir
(
const
std
::
string
&
path
)
{
return
utils
::
prefix_dir_from_env
(
path
,
"SNAP"
);
}
std
::
string
in_snap_data_dir
(
const
std
::
string
&
path
)
{
return
utils
::
prefix_dir_from_env
(
path
,
"SNAP_COMMON"
);
}
#include <cstring>
std
::
string
in_snap_user_data_dir
(
const
std
::
string
&
path
)
{
return
utils
::
prefix_dir_from_env
(
path
,
"SNAP_USER_COMMON"
);
}
namespace
fs
=
boost
::
filesystem
;
std
::
string
home_dir
()
{
namespace
{
static
std
::
string
runtime_dir
()
{
static
std
::
string
path
;
if
(
path
.
empty
())
{
path
=
utils
::
get_env_value
(
"HOME
"
,
""
);
path
=
anbox
::
utils
::
get_env_value
(
"XDG_RUNTIME_DIR
"
,
""
);
if
(
path
.
empty
())
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"No
ho
me directory specified"
));
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"No
runti
me directory specified"
));
}
return
path
;
}
std
::
string
runtime_dir
()
{
static
std
::
string
path
;
if
(
path
.
empty
())
{
path
=
utils
::
get_env_value
(
"XDG_RUNTIME_DIR"
,
""
);
if
(
path
.
empty
())
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"No runtime directory specified"
));
}
return
path
;
}
std
::
string
state_dir
()
{
static
std
::
string
path
=
"/var/lib"
;
return
path
;
void
anbox
::
SystemConfiguration
::
set_data_path
(
const
std
::
string
&
path
)
{
data_path
=
path
;
}
std
::
string
log_path
()
{
static
std
::
string
path
=
in_snap_data_dir
(
utils
::
string_format
(
"%s/anbox/"
,
state_dir
()));
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
rootfs_dir
()
const
{
return
(
data_path
/
"rootfs"
).
string
();
}
std
::
string
socket_path
()
{
static
std
::
string
path
=
utils
::
string_format
(
"%s/anbox/sockets"
,
runtime_dir
());
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
log_dir
()
const
{
return
(
data_path
/
"logs"
).
string
();
}
std
::
string
data_path
()
{
static
std
::
string
path
=
utils
::
string_format
(
"%s/.anbox/data"
,
home_dir
());
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
container_config_dir
()
const
{
return
(
data_path
/
"containers"
).
string
();
}
std
::
string
rootfs_path
()
{
static
std
::
string
path
=
in_snap_data_dir
(
utils
::
string_format
(
"%s/anbox/rootfs"
,
state_dir
()));
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
container_socket_path
()
const
{
return
"/run/anbox-container.socket"
;
}
std
::
string
container_config_path
()
{
static
std
::
string
path
=
in_snap_data_dir
(
utils
::
string_format
(
"%s/anbox/containers"
,
state_dir
()));
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
socket_dir
()
const
{
static
std
::
string
dir
=
anbox
::
utils
::
string_format
(
"%s/anbox/sockets"
,
runtime_dir
());
return
dir
;
}
std
::
string
container_socket_path
()
{
st
d
::
string
path
=
"/run/anbox-container.socket"
;
return
path
;
std
::
string
anbox
::
SystemConfiguration
::
input_device_dir
()
const
{
st
atic
std
::
string
dir
=
anbox
::
utils
::
string_format
(
"%s/anbox/input"
,
runtime_dir
())
;
return
dir
;
}
std
::
string
host_input_device_path
()
{
static
std
::
string
path
=
utils
::
string_format
(
"%s/anbox/input-devices"
,
runtime_dir
());
return
path
;
anbox
::
SystemConfiguration
&
anbox
::
SystemConfiguration
::
instance
()
{
static
SystemConfiguration
config
;
return
config
;
}
}
// namespace config
}
// namespace anbox
src/anbox/config.h
浏览文件 @
e1aff472
...
...
@@ -19,20 +19,32 @@
#define ANBOX_CONFIG_H_
#include <string>
#include <memory>
#include <boost/filesystem.hpp>
namespace
anbox
{
namespace
config
{
std
::
string
in_snap_dir
(
const
std
::
string
&
path
);
std
::
string
in_snap_data_dir
(
const
std
::
string
&
path
);
std
::
string
in_snap_user_data_dir
(
const
std
::
string
&
path
);
std
::
string
data_path
();
std
::
string
rootfs_path
();
std
::
string
log_path
();
std
::
string
socket_path
();
std
::
string
container_config_path
();
std
::
string
container_socket_path
();
std
::
string
host_input_device_path
();
}
// namespace config
class
SystemConfiguration
{
public:
static
SystemConfiguration
&
instance
();
virtual
~
SystemConfiguration
()
=
default
;
void
set_data_path
(
const
std
::
string
&
path
);
std
::
string
rootfs_dir
()
const
;
std
::
string
log_dir
()
const
;
std
::
string
socket_dir
()
const
;
std
::
string
container_config_dir
()
const
;
std
::
string
container_socket_path
()
const
;
std
::
string
input_device_dir
()
const
;
protected:
SystemConfiguration
()
=
default
;
boost
::
filesystem
::
path
data_path
=
"/var/lib/anbox"
;
};
}
// namespace anbox
#endif
src/anbox/container/client.cpp
浏览文件 @
e1aff472
...
...
@@ -31,7 +31,7 @@ namespace anbox {
namespace
container
{
Client
::
Client
(
const
std
::
shared_ptr
<
Runtime
>
&
rt
)
:
messenger_
(
std
::
make_shared
<
network
::
LocalSocketMessenger
>
(
config
::
container_socket_path
(),
rt
)),
SystemConfiguration
::
instance
().
container_socket_path
(),
rt
)),
pending_calls_
(
std
::
make_shared
<
rpc
::
PendingCallCache
>
()),
rpc_channel_
(
std
::
make_shared
<
rpc
::
Channel
>
(
pending_calls_
,
messenger_
)),
management_api_
(
std
::
make_shared
<
ManagementApiStub
>
(
rpc_channel_
)),
...
...
src/anbox/container/lxc_container.cpp
浏览文件 @
e1aff472
...
...
@@ -38,7 +38,8 @@ namespace container {
LxcContainer
::
LxcContainer
(
const
network
::
Credentials
&
creds
)
:
state_
(
State
::
inactive
),
container_
(
nullptr
),
creds_
(
creds
)
{
utils
::
ensure_paths
({
config
::
container_config_path
(),
config
::
log_path
(),
SystemConfiguration
::
instance
().
container_config_dir
(),
SystemConfiguration
::
instance
().
log_dir
(),
});
}
...
...
@@ -78,28 +79,23 @@ void LxcContainer::setup_id_maps() {
void
LxcContainer
::
start
(
const
Configuration
&
configuration
)
{
if
(
getuid
()
!=
0
)
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"You have to start the container as root"
));
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"You have to start the container as root"
));
if
(
container_
&&
container_
->
is_running
(
container_
))
{
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"Container already started, stopping it now"
));
WARNING
(
"Container already started, stopping it now"
);
container_
->
stop
(
container_
);
}
if
(
!
container_
)
{
DEBUG
(
"Containers are stored in %s"
,
config
::
container_config_path
());
const
auto
container_config_dir
=
SystemConfiguration
::
instance
().
container_config_dir
();
DEBUG
(
"Containers are stored in %s"
,
container_config_dir
);
// Remove container config to be be able to rewrite it
::
unlink
(
utils
::
string_format
(
"%s/default/config"
,
config
::
container_config_path
())
.
c_str
());
::
unlink
(
utils
::
string_format
(
"%s/default/config"
,
container_config_dir
).
c_str
());
container_
=
lxc_container_new
(
"default"
,
config
::
container_config_path
().
c_str
());
container_
=
lxc_container_new
(
"default"
,
container_config_dir
.
c_str
());
if
(
!
container_
)
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"Failed to create LXC container instance"
));
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"Failed to create LXC container instance"
));
// If container is still running (for example after a crash) we stop it here
// to ensure
...
...
@@ -128,13 +124,13 @@ void LxcContainer::start(const Configuration &configuration) {
set_config_item
(
"lxc.init_cmd"
,
"/anbox-init.sh"
);
set_config_item
(
"lxc.rootfs.backend"
,
"dir"
);
DEBUG
(
"Using rootfs path %s"
,
config
::
rootfs_path
());
set_config_item
(
"lxc.rootfs"
,
config
::
rootfs_path
());
const
auto
rootfs_path
=
SystemConfiguration
::
instance
().
rootfs_dir
();
DEBUG
(
"Using rootfs path %s"
,
rootfs_path
);
set_config_item
(
"lxc.rootfs"
,
rootfs_path
);
set_config_item
(
"lxc.loglevel"
,
"0"
);
set_config_item
(
"lxc.logfile"
,
utils
::
string_format
(
"%s/container.log"
,
config
::
log_path
()).
c_str
());
const
auto
log_path
=
SystemConfiguration
::
instance
().
log_dir
();
set_config_item
(
"lxc.logfile"
,
utils
::
string_format
(
"%s/container.log"
,
log_path
).
c_str
());
if
(
fs
::
exists
(
"/sys/class/net/anboxbr0"
))
{
set_config_item
(
"lxc.network.type"
,
"veth"
);
...
...
@@ -178,7 +174,7 @@ void LxcContainer::start(const Configuration &configuration) {
// when running in confined environments like snap's.
if
(
!
utils
::
string_starts_with
(
target_path
,
"/"
))
target_path
=
std
::
string
(
"/"
)
+
target_path
;
target_path
=
config
::
rootfs_path
()
+
target_path
;
target_path
=
rootfs_path
+
target_path
;
set_config_item
(
"lxc.mount.entry"
,
...
...
@@ -213,8 +209,7 @@ void LxcContainer::stop() {
void
LxcContainer
::
set_config_item
(
const
std
::
string
&
key
,
const
std
::
string
&
value
)
{
if
(
!
container_
->
set_config_item
(
container_
,
key
.
c_str
(),
value
.
c_str
()))
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"Failed to configure LXC container"
));
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"Failed to configure LXC container"
));
}
Container
::
State
LxcContainer
::
state
()
{
return
state_
;
}
...
...
src/anbox/container/service.cpp
浏览文件 @
e1aff472
...
...
@@ -38,12 +38,11 @@ std::shared_ptr<Service> Service::create(const std::shared_ptr<Runtime> &rt) {
[
sp
](
std
::
shared_ptr
<
boost
::
asio
::
local
::
stream_protocol
::
socket
>
const
&
socket
)
{
sp
->
new_client
(
socket
);
});
sp
->
connector_
=
std
::
make_shared
<
network
::
PublishedSocketConnector
>
(
config
::
container_socket_path
()
,
rt
,
delegate_connector
);
const
auto
container_socket_path
=
SystemConfiguration
::
instance
().
container_socket_path
();
sp
->
connector_
=
std
::
make_shared
<
network
::
PublishedSocketConnector
>
(
container_socket_path
,
rt
,
delegate_connector
);
// Make sure others can connect to our socket
::
chmod
(
config
::
container_socket_path
().
c_str
(),
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
|
S_IWOTH
);
::
chmod
(
container_socket_path
.
c_str
(),
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IWGRP
|
S_IROTH
|
S_IWOTH
);
DEBUG
(
"Everything setup. Waiting for incoming connections."
);
...
...
src/anbox/input/manager.cpp
浏览文件 @
e1aff472
...
...
@@ -26,7 +26,7 @@
namespace
anbox
{
namespace
input
{
Manager
::
Manager
(
const
std
::
shared_ptr
<
Runtime
>
&
runtime
)
:
runtime_
(
runtime
)
{
utils
::
ensure_paths
({
config
::
host_input_device_path
()});
utils
::
ensure_paths
({
SystemConfiguration
::
instance
().
input_device_dir
()});
}
Manager
::~
Manager
()
{}
...
...
@@ -45,8 +45,7 @@ std::uint32_t Manager::next_id() {
}
std
::
string
Manager
::
build_device_path
(
const
std
::
uint32_t
&
id
)
{
return
(
boost
::
format
(
"%1%/event%2%"
)
%
config
::
host_input_device_path
()
%
id
)
.
str
();
return
(
boost
::
format
(
"%1%/event%2%"
)
%
SystemConfiguration
::
instance
().
input_device_dir
()
%
id
).
str
();
}
}
// namespace input
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录