]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: handle gracefully if we can't read oom_kill cgroup attribute
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Oct 2021 08:39:12 +0000 (10:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Oct 2021 08:45:22 +0000 (10:45 +0200)
src/core/cgroup.c

index 931b31e2e1874db67a050759d9f130405058b675..3c4602d0962ff4f6c52de72d89e17396a3755cf9 100644 (file)
@@ -3043,12 +3043,15 @@ int unit_check_oom(Unit *u) {
                 return 0;
 
         r = cg_get_keyed_attribute("memory", u->cgroup_path, "memory.events", STRV_MAKE("oom_kill"), &oom_kill);
-        if (r < 0)
+        if (IN_SET(r, -ENOENT, -ENXIO)) /* Handle gracefully if cgroup or oom_kill attribute don't exist */
+                c = 0;
+        else if (r < 0)
                 return log_unit_debug_errno(u, r, "Failed to read oom_kill field of memory.events cgroup attribute: %m");
-
-        r = safe_atou64(oom_kill, &c);
-        if (r < 0)
-                return log_unit_debug_errno(u, r, "Failed to parse oom_kill field: %m");
+        else {
+                r = safe_atou64(oom_kill, &c);
+                if (r < 0)
+                        return log_unit_debug_errno(u, r, "Failed to parse oom_kill field: %m");
+        }
 
         increased = c > u->oom_kill_last;
         u->oom_kill_last = c;