]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/cgroup: CGContext must be available if Unit has CGRuntime
authorMike Yuan <me@yhndnzj.com>
Wed, 24 Dec 2025 18:15:29 +0000 (19:15 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 27 Dec 2025 19:14:56 +0000 (20:14 +0100)
Follow-up for e03e5056dbffffafc86e46985658e1c9075d3c74

src/core/cgroup.c
src/core/unit.c

index 33d0ab5adde390bbf30b1f544d24071825592929..6e6d6068544df6abdca699a2911ae619b2565861 100644 (file)
@@ -3050,9 +3050,7 @@ int unit_check_oom(Unit *u) {
         if (!crt || !crt->cgroup_path)
                 return 0;
 
-        CGroupContext *ctx = unit_get_cgroup_context(u);
-        if (!ctx)
-                return 0;
+        CGroupContext *ctx = ASSERT_PTR(unit_get_cgroup_context(u));
 
         /* If memory.oom.group=1, then look up the oom_group_kill field, which reports how many times the
          * kernel killed every process recursively in this cgroup and its descendants, similar to
index 7161c1cb6c44d55eb3462a5298c291653a85a2a3..4287179903e37b51a34d4b289b31c9872906e7f0 100644 (file)
@@ -5141,12 +5141,11 @@ int unit_setup_exec_runtime(Unit *u) {
         return r;
 }
 
-CGroupRuntime *unit_setup_cgroup_runtime(Unit *u) {
-        size_t offset;
-
+CGroupRuntime* unit_setup_cgroup_runtime(Unit *u) {
         assert(u);
+        assert(UNIT_HAS_CGROUP_CONTEXT(u));
 
-        offset = UNIT_VTABLE(u)->cgroup_runtime_offset;
+        size_t offset = UNIT_VTABLE(u)->cgroup_runtime_offset;
         assert(offset > 0);
 
         CGroupRuntime **rt = (CGroupRuntime**) ((uint8_t*) u + offset);