From 56d83b74d45e0d6936ba44a524fe8b2c2237c833 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 30 Jun 2023 15:50:33 +0200 Subject: [PATCH] oom: don't encode whether unit types can do oomd hookup a second time We already encode this in UnitVTable, hence use it. Even if it means we'll do some minor extra iterations. --- src/core/core-varlink.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c index 843271593d..aa4c047418 100644 --- a/src/core/core-varlink.c +++ b/src/core/core-varlink.c @@ -146,7 +146,6 @@ int manager_varlink_send_managed_oom_update(Unit *u) { } static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) { - static const UnitType supported_unit_types[] = { UNIT_SLICE, UNIT_SERVICE, UNIT_SCOPE }; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *arr = NULL; int r; @@ -157,8 +156,12 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) { if (r < 0) return r; - for (size_t i = 0; i < ELEMENTSOF(supported_unit_types); i++) - LIST_FOREACH(units_by_type, u, m->units_by_type[supported_unit_types[i]]) { + for (UnitType t = 0; t < _UNIT_TYPE_MAX; t++) { + + if (!unit_vtable[t]->can_set_managed_oom) + continue; + + LIST_FOREACH(units_by_type, u, m->units_by_type[t]) { CGroupContext *c; if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u))) @@ -186,6 +189,7 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) { return r; } } + } r = json_build(&v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("cgroups", JSON_BUILD_VARIANT(arr)))); if (r < 0) -- 2.25.1