1 Star 0 Fork 50

zhongling.h/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0113-nspawn-simplify-machine-terminate-bus-call.patch 3.96 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 13:59 . import systemd-239-29.el8.src.rpm
From 74640adc3e79064ab34f7ced59e231603c58f07c Mon Sep 17 00:00:00 2001
From: Lennart Poettering <[email protected]>
Date: Fri, 5 Oct 2018 22:54:57 +0200
Subject: [PATCH] nspawn: simplify machine terminate bus call
We have the machine name anyway, let's use TerminateMachine() on
machined's Manager object directly with it. That way it's a single
method call only, instead of two, to terminate the machine.
(cherry picked from commit 11d81e506ed68c6c5cebe319dc57a9a2fc4319c5)
Resolves: #1697893
---
src/nspawn/nspawn-register.c | 34 +++++++---------------------------
src/nspawn/nspawn-register.h | 2 +-
src/nspawn/nspawn.c | 2 +-
3 files changed, 9 insertions(+), 29 deletions(-)
diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c
index 85f3cf1c01..e459cb63ec 100644
--- a/src/nspawn/nspawn-register.c
+++ b/src/nspawn/nspawn-register.c
@@ -201,10 +201,11 @@ int register_machine(
return 0;
}
-int terminate_machine(sd_bus *bus, pid_t pid) {
+int terminate_machine(
+ sd_bus *bus,
+ const char *machine_name) {
+
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- const char *path;
int r;
assert(bus);
@@ -214,32 +215,11 @@ int terminate_machine(sd_bus *bus, pid_t pid) {
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
- "GetMachineByPID",
- &error,
- &reply,
- "u",
- (uint32_t) pid);
- if (r < 0) {
- /* Note that the machine might already have been
- * cleaned up automatically, hence don't consider it a
- * failure if we cannot get the machine object. */
- log_debug("Failed to get machine: %s", bus_error_message(&error, r));
- return 0;
- }
-
- r = sd_bus_message_read(reply, "o", &path);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.machine1",
- path,
- "org.freedesktop.machine1.Machine",
- "Terminate",
+ "TerminateMachine",
&error,
NULL,
- NULL);
+ "s",
+ machine_name);
if (r < 0)
log_debug("Failed to terminate machine: %s", bus_error_message(&error, r));
diff --git a/src/nspawn/nspawn-register.h b/src/nspawn/nspawn-register.h
index 30807b9687..ddd8b053a3 100644
--- a/src/nspawn/nspawn-register.h
+++ b/src/nspawn/nspawn-register.h
@@ -8,6 +8,6 @@
#include "nspawn-mount.h"
int register_machine(sd_bus *bus, const char *machine_name, pid_t pid, const char *directory, sd_id128_t uuid, int local_ifindex, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties, bool keep_unit, const char *service);
-int terminate_machine(sd_bus *bus, pid_t pid);
+int terminate_machine(sd_bus *bus, const char *machine_name);
int allocate_scope(sd_bus *bus, const char *machine_name, pid_t pid, const char *slice, CustomMount *mounts, unsigned n_mounts, int kill_signal, char **properties);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 8aec893a69..c4943f6eb7 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -4066,7 +4066,7 @@ static int run(int master,
/* Kill if it is not dead yet anyway */
if (arg_register && !arg_keep_unit && bus)
- terminate_machine(bus, *pid);
+ terminate_machine(bus, arg_machine);
/* Normally redundant, but better safe than sorry */
(void) kill(*pid, SIGKILL);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhonglingh/systemd.git
[email protected]:zhonglingh/systemd.git
zhonglingh
systemd
systemd
a8

搜索帮助