]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/cgroup: check root cgroup earlier for unit_get_memory_accounting
authorMike Yuan <me@yhndnzj.com>
Thu, 13 Jun 2024 09:00:26 +0000 (11:00 +0200)
committerMike Yuan <me@yhndnzj.com>
Fri, 28 Jun 2024 13:43:20 +0000 (15:43 +0200)
src/core/cgroup.c

index 47413e6bc37a684451f7989f09728c64df936156..dfbe716e8bd4347e34d2aa6d7ce787ddfcc1d41b 100644 (file)
@@ -4527,6 +4527,10 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
         if (!UNIT_CGROUP_BOOL(u, memory_accounting))
                 return -ENODATA;
 
+        /* The root cgroup doesn't expose this information. */
+        if (unit_has_host_root_cgroup(u))
+                return -ENODATA;
+
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
         if (!crt)
                 return -ENODATA;
@@ -4534,10 +4538,6 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
                 /* If the cgroup is already gone, we try to find the last cached value. */
                 goto finish;
 
-        /* The root cgroup doesn't expose this information. */
-        if (unit_has_host_root_cgroup(u))
-                return -ENODATA;
-
         if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_MEMORY))
                 return -ENODATA;