Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
92757d4d
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
92757d4d
编写于
2月 02, 2016
作者:
M
Martin Kletzander
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
systemd: Add virSystemdGetMachineNameByPID
Signed-off-by:
N
Martin Kletzander
<
mkletzan@redhat.com
>
上级
9ba26462
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
105 addition
and
0 deletion
+105
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/util/virsystemd.c
src/util/virsystemd.c
+56
-0
src/util/virsystemd.h
src/util/virsystemd.h
+2
-0
tests/virsystemdtest.c
tests/virsystemdtest.c
+46
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
92757d4d
...
...
@@ -2274,6 +2274,7 @@ virSystemdCanHibernate;
virSystemdCanHybridSleep;
virSystemdCanSuspend;
virSystemdCreateMachine;
virSystemdGetMachineNameByPID;
virSystemdMakeMachineName;
virSystemdMakeScopeName;
virSystemdMakeSliceName;
...
...
src/util/virsystemd.c
浏览文件 @
92757d4d
...
...
@@ -113,6 +113,7 @@ char *virSystemdMakeSliceName(const char *partition)
return
virBufferContentAndReset
(
&
buf
);
}
char
*
virSystemdMakeMachineName
(
const
char
*
name
,
const
char
*
drivername
,
bool
privileged
)
...
...
@@ -139,6 +140,61 @@ char *virSystemdMakeMachineName(const char *name,
return
machinename
;
}
char
*
virSystemdGetMachineNameByPID
(
pid_t
pid
)
{
DBusConnection
*
conn
;
DBusMessage
*
reply
;
char
*
name
=
NULL
,
*
object
=
NULL
;
if
(
virDBusIsServiceEnabled
(
"org.freedesktop.machine1"
)
<
0
)
goto
cleanup
;
if
(
virDBusIsServiceRegistered
(
"org.freedesktop.systemd1"
)
<
0
)
goto
cleanup
;
if
(
!
(
conn
=
virDBusGetSystemBus
()))
goto
cleanup
;
if
(
virDBusCallMethod
(
conn
,
&
reply
,
NULL
,
"org.freedesktop.machine1"
,
"/org/freedesktop/machine1"
,
"org.freedesktop.machine1.Manager"
,
"GetMachineByPID"
,
"u"
,
pid
)
<
0
)
goto
cleanup
;
if
(
virDBusMessageRead
(
reply
,
"o"
,
&
object
)
<
0
)
goto
cleanup
;
VIR_DEBUG
(
"Domain with pid %llu has object path '%s'"
,
(
unsigned
long
long
)
pid
,
object
);
if
(
virDBusCallMethod
(
conn
,
&
reply
,
NULL
,
"org.freedesktop.machine1"
,
object
,
"org.freedesktop.DBus.Properties"
,
"Get"
,
"ss"
,
"org.freedesktop.machine1.Machine"
,
"Name"
)
<
0
)
goto
cleanup
;
if
(
virDBusMessageRead
(
reply
,
"v"
,
"s"
,
&
name
)
<
0
)
goto
cleanup
;
VIR_DEBUG
(
"Domain with pid %llu has machine name '%s'"
,
(
unsigned
long
long
)
pid
,
name
);
cleanup:
VIR_FREE
(
object
);
dbus_message_unref
(
reply
);
return
name
;
}
/**
* virSystemdCreateMachine:
* @name: driver unique name of the machine
...
...
src/util/virsystemd.h
浏览文件 @
92757d4d
...
...
@@ -55,4 +55,6 @@ int virSystemdCanHibernate(bool *result);
int
virSystemdCanHybridSleep
(
bool
*
result
);
char
*
virSystemdGetMachineNameByPID
(
pid_t
pid
);
#endif
/* __VIR_SYSTEMD_H__ */
tests/virsystemdtest.c
浏览文件 @
92757d4d
...
...
@@ -54,6 +54,31 @@ VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
"Something went wrong creating the machine"
);
}
else
{
reply
=
dbus_message_new
(
DBUS_MESSAGE_TYPE_METHOD_RETURN
);
if
(
STREQ
(
member
,
"GetMachineByPID"
))
{
const
char
*
object_path
=
"/org/freedesktop/machine1/machine/qemu_2ddemo"
;
DBusMessageIter
iter
;
dbus_message_iter_init_append
(
reply
,
&
iter
);
if
(
!
dbus_message_iter_append_basic
(
&
iter
,
DBUS_TYPE_OBJECT_PATH
,
&
object_path
))
goto
error
;
}
else
if
(
STREQ
(
member
,
"Get"
))
{
const
char
*
name
=
"qemu-demo"
;
DBusMessageIter
iter
;
DBusMessageIter
sub
;
dbus_message_iter_init_append
(
reply
,
&
iter
);
dbus_message_iter_open_container
(
&
iter
,
DBUS_TYPE_VARIANT
,
"s"
,
&
sub
);
if
(
!
dbus_message_iter_append_basic
(
&
sub
,
DBUS_TYPE_STRING
,
&
name
))
goto
error
;
dbus_message_iter_close_container
(
&
iter
,
&
sub
);
}
}
}
else
if
(
STREQ
(
service
,
"org.freedesktop.login1"
))
{
char
*
supported
=
getenv
(
"RESULT_SUPPORT"
);
...
...
@@ -338,6 +363,25 @@ static int testCreateNetwork(const void *opaque ATTRIBUTE_UNUSED)
}
static
int
testGetMachineName
(
const
void
*
opaque
ATTRIBUTE_UNUSED
)
{
char
*
tmp
=
virSystemdGetMachineNameByPID
(
1234
);
int
ret
=
-
1
;
if
(
!
tmp
)
{
fprintf
(
stderr
,
"%s"
,
"Failed to create LXC machine
\n
"
);
return
ret
;
}
if
(
STREQ
(
tmp
,
"qemu-demo"
))
ret
=
0
;
VIR_FREE
(
tmp
);
return
ret
;
}
struct
testNameData
{
const
char
*
name
;
const
char
*
expected
;
...
...
@@ -491,6 +535,8 @@ mymain(void)
ret
=
-
1
;
if
(
virtTestRun
(
"Test create with network "
,
testCreateNetwork
,
NULL
)
<
0
)
ret
=
-
1
;
if
(
virtTestRun
(
"Test getting machine name "
,
testGetMachineName
,
NULL
)
<
0
)
ret
=
-
1
;
# define TEST_SCOPE(name, unitname) \
do { \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录