1 Star 0 Fork 49

zhangwenlong01/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0747-shared-dropin-fix-assert-for-invalid-drop-in.patch 3.86 KB
一键复制 编辑 原始数据 按行查看 历史
小龙 提交于 2023-01-12 18:39 . update to systemd-239-68.el8_7.1
From 9e1e02a83538a865dae65454214363d306e69854 Mon Sep 17 00:00:00 2001
From: Topi Miettinen <toiwoton@gmail.com>
Date: Tue, 17 Dec 2019 15:47:37 +0200
Subject: [PATCH] shared/dropin: fix assert for invalid drop-in
Don't try to show top level drop-in for non-existent units or when trying to
instantiate non-instantiated units:
$ systemctl cat nonexistent@.service
Assertion 'name' failed at src/shared/dropin.c:143, function unit_file_find_dirs(). Aborting.
$ systemctl cat systemd-journald@.service
Assertion 'name' failed at src/shared/dropin.c:143, function unit_file_find_dirs(). Aborting.
(cherry picked from commit 7a670b1dd981c645064f69faf85b04620aadbafb)
Resolves: #2051520
---
src/shared/dropin.c | 23 ++++++++++++-----------
test/TEST-15-DROPIN/test-dropin.sh | 14 ++++++++++++++
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index bd2a3c0feb..11ed4c7184 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -236,7 +236,6 @@ int unit_file_find_dropin_paths(
char ***ret) {
_cleanup_strv_free_ char **dirs = NULL;
- UnitType type = _UNIT_TYPE_INVALID;
char *name, **p;
Iterator i;
int r;
@@ -246,22 +245,24 @@ int unit_file_find_dropin_paths(
/* All the names in the unit are of the same type so just grab one. */
name = (char*) set_first(names);
if (name) {
+ UnitType type = _UNIT_TYPE_INVALID;
+
type = unit_name_to_type(name);
if (type < 0)
return log_error_errno(EINVAL,
"Failed to to derive unit type from unit name: %s",
name);
- }
- /* Special top level drop in for "<unit type>.<suffix>". Add this first as it's the most generic
- * and should be able to be overridden by more specific drop-ins. */
- STRV_FOREACH(p, lookup_path)
- (void) unit_file_find_dirs(original_root,
- unit_path_cache,
- *p,
- unit_type_to_string(type),
- dir_suffix,
- &dirs);
+ /* Special top level drop in for "<unit type>.<suffix>". Add this first as it's the most generic
+ * and should be able to be overridden by more specific drop-ins. */
+ STRV_FOREACH(p, lookup_path)
+ (void) unit_file_find_dirs(original_root,
+ unit_path_cache,
+ *p,
+ unit_type_to_string(type),
+ dir_suffix,
+ &dirs);
+ }
SET_FOREACH(name, names, i)
STRV_FOREACH(p, lookup_path)
diff --git a/test/TEST-15-DROPIN/test-dropin.sh b/test/TEST-15-DROPIN/test-dropin.sh
index 7836c6535d..5419169f7b 100755
--- a/test/TEST-15-DROPIN/test-dropin.sh
+++ b/test/TEST-15-DROPIN/test-dropin.sh
@@ -289,9 +289,23 @@ EOF
clear_services a b
}
+test_invalid_dropins () {
+ echo "Testing invalid dropins..."
+ # Assertion failed on earlier versions, command exits unsuccessfully on later versions
+ systemctl cat nonexistent@.service || true
+ create_services a
+ systemctl daemon-reload
+ # Assertion failed on earlier versions, command exits unsuccessfully on later versions
+ systemctl cat a@.service || true
+ systemctl stop a
+ clear_services a
+ return 0
+}
+
test_basic_dropins
test_template_dropins
test_alias_dropins
test_masked_dropins
+test_invalid_dropins
touch /testok
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangwenlong01/systemd.git
git@gitee.com:zhangwenlong01/systemd.git
zhangwenlong01
systemd
systemd
a8

搜索帮助

0d507c66 1850385 C8b1a773 1850385