summaryrefslogtreecommitdiffstats
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-10-06 18:24:46 +0200
committerLennart Poettering <lennart@poettering.net>2023-10-06 18:24:50 +0200
commitd46510de2fe7ce23a17efab6a881b53b7f4a9b38 (patch)
treee4ac357727a5863d6b45ac01e5f13eac65beffa8 /src/core/cgroup.c
parentcgroup: drop cgroup path parameter from xattr calls (diff)
downloadsystemd-d46510de2fe7ce23a17efab6a881b53b7f4a9b38.tar.xz
systemd-d46510de2fe7ce23a17efab6a881b53b7f4a9b38.zip
cgroup: refactor cgroup_xattr_apply()
Split the function up, so that each set of xattrs is applied separately.
Diffstat (limited to '')
-rw-r--r--src/core/cgroup.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 39e670091f..5f8407c480 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -878,19 +878,11 @@ int cgroup_log_xattr_apply(Unit *u) {
return 0;
}
-static void cgroup_xattr_apply(Unit *u) {
+static void cgroup_invocation_id_xattr_apply(Unit *u) {
bool b;
- int r;
assert(u);
- /* The 'user.*' xattrs can be set from a user manager. */
- cgroup_oomd_xattr_apply(u);
- cgroup_log_xattr_apply(u);
-
- if (!MANAGER_IS_SYSTEM(u->manager))
- return;
-
b = !sd_id128_is_null(u->invocation_id);
FOREACH_STRING(xn, "trusted.invocation_id", "user.invocation_id") {
if (b)
@@ -898,6 +890,12 @@ static void cgroup_xattr_apply(Unit *u) {
else
unit_remove_xattr_graceful(u, xn);
}
+}
+
+static void cgroup_delegate_xattr_apply(Unit *u) {
+ bool b;
+
+ assert(u);
/* Indicate on the cgroup whether delegation is on, via an xattr. This is best-effort, as old kernels
* didn't support xattrs on cgroups at all. Later they got support for setting 'trusted.*' xattrs,
@@ -914,6 +912,12 @@ static void cgroup_xattr_apply(Unit *u) {
else
unit_remove_xattr_graceful(u, xn);
}
+}
+
+static void cgroup_survive_xattr_apply(Unit *u) {
+ int r;
+
+ assert(u);
if (u->survive_final_kill_signal) {
r = cg_set_xattr(
@@ -942,6 +946,21 @@ static void cgroup_xattr_apply(Unit *u) {
}
}
+static void cgroup_xattr_apply(Unit *u) {
+ assert(u);
+
+ /* The 'user.*' xattrs can be set from a user manager. */
+ cgroup_oomd_xattr_apply(u);
+ cgroup_log_xattr_apply(u);
+
+ if (!MANAGER_IS_SYSTEM(u->manager))
+ return;
+
+ cgroup_invocation_id_xattr_apply(u);
+ cgroup_delegate_xattr_apply(u);
+ cgroup_survive_xattr_apply(u);
+}
+
static int lookup_block_device(const char *p, dev_t *ret) {
dev_t rdev, dev = 0;
mode_t mode;