From f4a6a30ae524a0402c7839cef74385bacdeafec9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Jan 2018 13:06:48 +0100 Subject: [PATCH] core: unify call we use to synthesize cgroup empty events when we stopped watching any unit PIDs This code is very similar in scope and service units, let's unify it in one function. This changes little for service units, but for scope units makes sure we go through the cgroup queue, which is something we should do anyway. --- src/core/cgroup.c | 25 +++++++++++++++++++++++++ src/core/cgroup.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 46eace7cb..8124704ca 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1828,6 +1828,31 @@ static int unit_watch_pids_in_path(Unit *u, const char *path) { return ret; } +int unit_synthesize_cgroup_empty_event(Unit *u) { + int r; + + assert(u); + + /* Enqueue a synthetic cgroup empty event if this unit doesn't watch any PIDs anymore. This is compatibility + * support for non-unified systems where notifications aren't reliable, and hence need to take whatever we can + * get as notification source as soon as we stopped having any useful PIDs to watch for. */ + + if (!u->cgroup_path) + return -ENOENT; + + r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); + if (r < 0) + return r; + if (r > 0) /* On unified we have reliable notifications, and don't need this */ + return 0; + + if (!set_isempty(u->pids)) + return 0; + + unit_add_to_cgroup_empty_queue(u); + return 0; +} + int unit_watch_all_pids(Unit *u) { int r; diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 159fac4a4..1c43c0d14 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -197,6 +197,8 @@ Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); int unit_search_main_pid(Unit *u, pid_t *ret); int unit_watch_all_pids(Unit *u); +int unit_synthesize_cgroup_empty_event(Unit *u); + int unit_get_memory_current(Unit *u, uint64_t *ret); int unit_get_tasks_current(Unit *u, uint64_t *ret); int unit_get_cpu_usage(Unit *u, nsec_t *ret); -- 2.30.2