chiark / gitweb /
core: unify call we use to synthesize cgroup empty events when we stopped watching...
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Jan 2018 12:06:48 +0000 (13:06 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:50:15 +0000 (07:50 +0200)
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
src/core/cgroup.h

index 46eace7cb97d6a348f01c8f5ee09561b35011dd4..8124704cab094fa387397dbb855b537da2651564 100644 (file)
@@ -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;
 
index 159fac4a49f37e950fe863b3800379f64e0402ff..1c43c0d148bc1c52b282ae59291707bc006394ed 100644 (file)
@@ -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);