From fc594dee9848292ed381ab4e5be82f583c4fe7be Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Oct 2021 10:39:12 +0200 Subject: [PATCH 1/2] cgroup: handle gracefully if we can't read oom_kill cgroup attribute --- src/core/cgroup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 931b31e2e1..3c4602d096 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -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; From 1d1ba68816be40b94b2b64dd9f15b20b21cdf845 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Oct 2021 10:39:32 +0200 Subject: [PATCH 2/2] varlink: don't try to talk to oomd from unit tests Talking to external daemons we ourselves maintain is a job for the integration tests, not the unit tests. This communication is likely to fail hence don#t even bother. This makes our tests a bit cleaner. --- src/core/core-varlink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c index 04d9d96417..ab0d455380 100644 --- a/src/core/core-varlink.c +++ b/src/core/core-varlink.c @@ -562,6 +562,9 @@ static int manager_varlink_init_user(Manager *m) { if (m->managed_oom_varlink) return 1; + if (MANAGER_IS_TEST_RUN(m)) + return 0; + r = varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_USER); if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) { log_debug("systemd-oomd varlink unix socket not found, skipping user manager varlink setup");