!231 [sync] PR-230: core: use empty_to_root for cgroup path in log messages
From: @openeuler-sync-bot Reviewed-by: @overweight Signed-off-by: @overweight
This commit is contained in:
commit
a33b042987
@ -0,0 +1,41 @@
|
||||
From 0cddb53c85588fbfb8043f622895c7bd15819198 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Thu, 5 Aug 2021 03:13:48 +0900
|
||||
Subject: [PATCH 1/2] core/cgroup: fix error handling of cg_remove_xattr()
|
||||
|
||||
---
|
||||
src/core/cgroup.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
|
||||
index e5fd6672bb..83bd97327d 100644
|
||||
--- a/src/core/cgroup.c
|
||||
+++ b/src/core/cgroup.c
|
||||
@@ -717,13 +717,13 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
|
||||
|
||||
if (c->moom_preference != MANAGED_OOM_PREFERENCE_AVOID) {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_avoid");
|
||||
- if (r != -ENODATA)
|
||||
+ if (r < 0 && r != -ENODATA)
|
||||
log_unit_debug_errno(u, r, "Failed to remove oomd_avoid flag on control group %s, ignoring: %m", cgroup_path);
|
||||
}
|
||||
|
||||
if (c->moom_preference != MANAGED_OOM_PREFERENCE_OMIT) {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_omit");
|
||||
- if (r != -ENODATA)
|
||||
+ if (r < 0 && r != -ENODATA)
|
||||
log_unit_debug_errno(u, r, "Failed to remove oomd_omit flag on control group %s, ignoring: %m", cgroup_path);
|
||||
}
|
||||
}
|
||||
@@ -755,7 +755,7 @@ static void cgroup_xattr_apply(Unit *u) {
|
||||
log_unit_debug_errno(u, r, "Failed to set delegate flag on control group %s, ignoring: %m", u->cgroup_path);
|
||||
} else {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "trusted.delegate");
|
||||
- if (r != -ENODATA)
|
||||
+ if (r < 0 && r != -ENODATA)
|
||||
log_unit_debug_errno(u, r, "Failed to remove delegate flag on control group %s, ignoring: %m", u->cgroup_path);
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,257 @@
|
||||
From 6178e2f88956e1900f445908ed053865cc22e879 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Thu, 5 Aug 2021 03:14:41 +0900
|
||||
Subject: [PATCH 2/2] core: wrap cgroup path with empty_to_root() in log
|
||||
messages
|
||||
|
||||
This fixes e.g. the following log message:
|
||||
---
|
||||
systemd[1]: -.slice: Failed to migrate controller cgroups from , ignoring: Read-only file system
|
||||
---
|
||||
---
|
||||
src/core/bpf-devices.c | 3 ++-
|
||||
src/core/cgroup.c | 46 +++++++++++++++++++++---------------------
|
||||
src/core/unit.c | 6 +++---
|
||||
3 files changed, 28 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/src/core/bpf-devices.c b/src/core/bpf-devices.c
|
||||
index 8a345a4498..4daa7f76b0 100644
|
||||
--- a/src/core/bpf-devices.c
|
||||
+++ b/src/core/bpf-devices.c
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "fileio.h"
|
||||
#include "nulstr-util.h"
|
||||
#include "parse-util.h"
|
||||
+#include "path-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
@@ -260,7 +261,7 @@ int bpf_devices_apply_policy(
|
||||
r = bpf_program_cgroup_attach(prog, BPF_CGROUP_DEVICE, controller_path, BPF_F_ALLOW_MULTI);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Attaching device control BPF program to cgroup %s failed: %m",
|
||||
- cgroup_path);
|
||||
+ empty_to_root(cgroup_path));
|
||||
|
||||
finish:
|
||||
/* Unref the old BPF program (which will implicitly detach it) right before attaching the new program. */
|
||||
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
|
||||
index 83bd97327d..da821465da 100644
|
||||
--- a/src/core/cgroup.c
|
||||
+++ b/src/core/cgroup.c
|
||||
@@ -84,7 +84,7 @@ static int set_attribute_and_warn(Unit *u, const char *controller, const char *a
|
||||
r = cg_set_attribute(controller, u->cgroup_path, attribute, value);
|
||||
if (r < 0)
|
||||
log_unit_full_errno(u, LOG_LEVEL_CGROUP_WRITE(r), r, "Failed to set '%s' attribute on '%s' to '%.*s': %m",
|
||||
- strna(attribute), isempty(u->cgroup_path) ? "/" : u->cgroup_path, (int) strcspn(value, NEWLINE), value);
|
||||
+ strna(attribute), empty_to_root(u->cgroup_path), (int) strcspn(value, NEWLINE), value);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -706,25 +706,25 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
|
||||
if (c->moom_preference == MANAGED_OOM_PREFERENCE_OMIT) {
|
||||
r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_omit", "1", 1, 0);
|
||||
if (r < 0)
|
||||
- log_unit_debug_errno(u, r, "Failed to set oomd_omit flag on control group %s, ignoring: %m", cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to set oomd_omit flag on control group %s, ignoring: %m", empty_to_root(cgroup_path));
|
||||
}
|
||||
|
||||
if (c->moom_preference == MANAGED_OOM_PREFERENCE_AVOID) {
|
||||
r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_avoid", "1", 1, 0);
|
||||
if (r < 0)
|
||||
- log_unit_debug_errno(u, r, "Failed to set oomd_avoid flag on control group %s, ignoring: %m", cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to set oomd_avoid flag on control group %s, ignoring: %m", empty_to_root(cgroup_path));
|
||||
}
|
||||
|
||||
if (c->moom_preference != MANAGED_OOM_PREFERENCE_AVOID) {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_avoid");
|
||||
if (r < 0 && r != -ENODATA)
|
||||
- log_unit_debug_errno(u, r, "Failed to remove oomd_avoid flag on control group %s, ignoring: %m", cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to remove oomd_avoid flag on control group %s, ignoring: %m", empty_to_root(cgroup_path));
|
||||
}
|
||||
|
||||
if (c->moom_preference != MANAGED_OOM_PREFERENCE_OMIT) {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, "user.oomd_omit");
|
||||
if (r < 0 && r != -ENODATA)
|
||||
- log_unit_debug_errno(u, r, "Failed to remove oomd_omit flag on control group %s, ignoring: %m", cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to remove oomd_omit flag on control group %s, ignoring: %m", empty_to_root(cgroup_path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ static void cgroup_xattr_apply(Unit *u) {
|
||||
sd_id128_to_string(u->invocation_id, ids), 32,
|
||||
0);
|
||||
if (r < 0)
|
||||
- log_unit_debug_errno(u, r, "Failed to set invocation ID on control group %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to set invocation ID on control group %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
}
|
||||
|
||||
if (unit_cgroup_delegate(u)) {
|
||||
@@ -752,11 +752,11 @@ static void cgroup_xattr_apply(Unit *u) {
|
||||
"1", 1,
|
||||
0);
|
||||
if (r < 0)
|
||||
- log_unit_debug_errno(u, r, "Failed to set delegate flag on control group %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to set delegate flag on control group %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
} else {
|
||||
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "trusted.delegate");
|
||||
if (r < 0 && r != -ENODATA)
|
||||
- log_unit_debug_errno(u, r, "Failed to remove delegate flag on control group %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to remove delegate flag on control group %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
}
|
||||
|
||||
cgroup_oomd_xattr_apply(u, u->cgroup_path);
|
||||
@@ -1913,12 +1913,12 @@ int unit_watch_cgroup(Unit *u) {
|
||||
* is not an error */
|
||||
return 0;
|
||||
|
||||
- return log_unit_error_errno(u, errno, "Failed to add control inotify watch descriptor for control group %s: %m", u->cgroup_path);
|
||||
+ return log_unit_error_errno(u, errno, "Failed to add control inotify watch descriptor for control group %s: %m", empty_to_root(u->cgroup_path));
|
||||
}
|
||||
|
||||
r = hashmap_put(u->manager->cgroup_control_inotify_wd_unit, INT_TO_PTR(u->cgroup_control_inotify_wd), u);
|
||||
if (r < 0)
|
||||
- return log_unit_error_errno(u, r, "Failed to add control inotify watch descriptor to hash map: %m");
|
||||
+ return log_unit_error_errno(u, r, "Failed to add control inotify watch descriptor for control group %s to hash map: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1976,12 +1976,12 @@ int unit_watch_cgroup_memory(Unit *u) {
|
||||
* is not an error */
|
||||
return 0;
|
||||
|
||||
- return log_unit_error_errno(u, errno, "Failed to add memory inotify watch descriptor for control group %s: %m", u->cgroup_path);
|
||||
+ return log_unit_error_errno(u, errno, "Failed to add memory inotify watch descriptor for control group %s: %m", empty_to_root(u->cgroup_path));
|
||||
}
|
||||
|
||||
r = hashmap_put(u->manager->cgroup_memory_inotify_wd_unit, INT_TO_PTR(u->cgroup_memory_inotify_wd), u);
|
||||
if (r < 0)
|
||||
- return log_unit_error_errno(u, r, "Failed to add memory inotify watch descriptor to hash map: %m");
|
||||
+ return log_unit_error_errno(u, r, "Failed to add memory inotify watch descriptor for control group %s to hash map: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2004,9 +2004,9 @@ int unit_pick_cgroup_path(Unit *u) {
|
||||
|
||||
r = unit_set_cgroup_path(u, path);
|
||||
if (r == -EEXIST)
|
||||
- return log_unit_error_errno(u, r, "Control group %s exists already.", path);
|
||||
+ return log_unit_error_errno(u, r, "Control group %s exists already.", empty_to_root(path));
|
||||
if (r < 0)
|
||||
- return log_unit_error_errno(u, r, "Failed to set unit's control group path to %s: %m", path);
|
||||
+ return log_unit_error_errno(u, r, "Failed to set unit's control group path to %s: %m", empty_to_root(path));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2034,7 +2034,7 @@ static int unit_update_cgroup(
|
||||
/* First, create our own group */
|
||||
r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, u->cgroup_path);
|
||||
if (r < 0)
|
||||
- return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", u->cgroup_path);
|
||||
+ return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(u->cgroup_path));
|
||||
created = r;
|
||||
|
||||
/* Start watching it */
|
||||
@@ -2050,7 +2050,7 @@ static int unit_update_cgroup(
|
||||
/* Enable all controllers we need */
|
||||
r = cg_enable_everywhere(u->manager->cgroup_supported, enable_mask, u->cgroup_path, &result_mask);
|
||||
if (r < 0)
|
||||
- log_unit_warning_errno(u, r, "Failed to enable/disable controllers on cgroup %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_warning_errno(u, r, "Failed to enable/disable controllers on cgroup %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
/* Remember what's actually enabled now */
|
||||
u->cgroup_enabled_mask = result_mask;
|
||||
@@ -2072,12 +2072,12 @@ static int unit_update_cgroup(
|
||||
if (cg_all_unified() == 0) {
|
||||
r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, u->cgroup_path, migrate_callback, u);
|
||||
if (r < 0)
|
||||
- log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE);
|
||||
r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, u->cgroup_path, !is_root_slice);
|
||||
if (r < 0)
|
||||
- log_unit_warning_errno(u, r, "Failed to delete controller cgroups %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_warning_errno(u, r, "Failed to delete controller cgroups %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
}
|
||||
|
||||
/* Set attributes */
|
||||
@@ -2167,7 +2167,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
|
||||
|
||||
log_unit_full_errno(u, again ? LOG_DEBUG : LOG_INFO, q,
|
||||
"Couldn't move process "PID_FMT" to%s requested cgroup '%s': %m",
|
||||
- pid, again ? " directly" : "", p);
|
||||
+ pid, again ? " directly" : "", empty_to_root(p));
|
||||
|
||||
if (again) {
|
||||
int z;
|
||||
@@ -2179,7 +2179,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
|
||||
|
||||
z = unit_attach_pid_to_cgroup_via_bus(u, pid, suffix_path);
|
||||
if (z < 0)
|
||||
- log_unit_info_errno(u, z, "Couldn't move process "PID_FMT" to requested cgroup '%s' (directly or via the system bus): %m", pid, p);
|
||||
+ log_unit_info_errno(u, z, "Couldn't move process "PID_FMT" to requested cgroup '%s' (directly or via the system bus): %m", pid, empty_to_root(p));
|
||||
else
|
||||
continue; /* When the bus thing worked via the bus we are fully done for this PID. */
|
||||
}
|
||||
@@ -2213,7 +2213,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
|
||||
continue; /* Success! */
|
||||
|
||||
log_unit_debug_errno(u, q, "Failed to attach PID " PID_FMT " to requested cgroup %s in controller %s, falling back to unit's cgroup: %m",
|
||||
- pid, p, cgroup_controller_to_string(c));
|
||||
+ pid, empty_to_root(p), cgroup_controller_to_string(c));
|
||||
}
|
||||
|
||||
/* So this controller is either not delegate or realized, or something else weird happened. In
|
||||
@@ -2648,7 +2648,7 @@ void unit_prune_cgroup(Unit *u) {
|
||||
* the containing slice is stopped. So even if we failed now, this unit shouldn't assume
|
||||
* that the cgroup is still realized the next time it is started. Do not return early
|
||||
* on error, continue cleanup. */
|
||||
- log_unit_full_errno(u, r == -EBUSY ? LOG_DEBUG : LOG_WARNING, r, "Failed to destroy cgroup %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_full_errno(u, r == -EBUSY ? LOG_DEBUG : LOG_WARNING, r, "Failed to destroy cgroup %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
if (is_root_slice)
|
||||
return;
|
||||
@@ -2861,7 +2861,7 @@ void unit_add_to_cgroup_empty_queue(Unit *u) {
|
||||
|
||||
r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path);
|
||||
if (r < 0) {
|
||||
- log_unit_debug_errno(u, r, "Failed to determine whether cgroup %s is empty: %m", u->cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to determine whether cgroup %s is empty: %m", empty_to_root(u->cgroup_path));
|
||||
return;
|
||||
}
|
||||
if (r == 0)
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index 6273926013..8ce94ccb75 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -427,7 +427,7 @@ bool unit_may_gc(Unit *u) {
|
||||
|
||||
r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path);
|
||||
if (r < 0)
|
||||
- log_unit_debug_errno(u, r, "Failed to determine whether cgroup %s is empty: %m", u->cgroup_path);
|
||||
+ log_unit_debug_errno(u, r, "Failed to determine whether cgroup %s is empty: %m", empty_to_root(u->cgroup_path));
|
||||
if (r <= 0)
|
||||
return false;
|
||||
}
|
||||
@@ -4548,7 +4548,7 @@ int unit_kill_context(
|
||||
log_func, u);
|
||||
if (r < 0) {
|
||||
if (!IN_SET(r, -EAGAIN, -ESRCH, -ENOENT))
|
||||
- log_unit_warning_errno(u, r, "Failed to kill control group %s, ignoring: %m", u->cgroup_path);
|
||||
+ log_unit_warning_errno(u, r, "Failed to kill control group %s, ignoring: %m", empty_to_root(u->cgroup_path));
|
||||
|
||||
} else if (r > 0) {
|
||||
|
||||
@@ -5006,7 +5006,7 @@ int unit_fork_helper_process(Unit *u, const char *name, pid_t *ret) {
|
||||
if (u->cgroup_path) {
|
||||
r = cg_attach_everywhere(u->manager->cgroup_supported, u->cgroup_path, 0, NULL, NULL);
|
||||
if (r < 0) {
|
||||
- log_unit_error_errno(u, r, "Failed to join unit cgroup %s: %m", u->cgroup_path);
|
||||
+ log_unit_error_errno(u, r, "Failed to join unit cgroup %s: %m", empty_to_root(u->cgroup_path));
|
||||
_exit(EXIT_CGROUP);
|
||||
}
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 249
|
||||
Release: 10
|
||||
Release: 11
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -79,6 +79,8 @@ Patch6009: backport-CVE-2021-3997-shared-rm-rf-loop-over-nested-directories
|
||||
Patch6010: backport-fix-CVE-2021-33910.patch
|
||||
Patch6011: backport-temporarily-disable-test-seccomp.patch
|
||||
Patch6012: backport-revert-core-map-io.bfq.weight-to-1.1000.patch
|
||||
Patch6013: backport-0001-core-cgroup-fix-error-handling-of-cg_remove_xattr.patch
|
||||
Patch6014: backport-0002-core-wrap-cgroup-path-with-empty_to_root-in-log-mess.patch
|
||||
|
||||
BuildRequires: gcc, gcc-c++
|
||||
BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel
|
||||
@ -1700,6 +1702,9 @@ fi
|
||||
%{_unitdir}/systemd-userdbd.socket
|
||||
|
||||
%changelog
|
||||
* Thu Mar 10 2022 xujing <xujing99@huawei.com> - 249-11
|
||||
- core: use empty_to_root for cgroup path in log messages
|
||||
|
||||
* Tue Mar 1 2022 yangmingtai <yangmingtai@huawei.com> - 249-10
|
||||
- revert :core map io.bfq.weight to 1..1000
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user