summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-01-12 13:06:48 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:50:15 +0200
commitf4a6a30ae524a0402c7839cef74385bacdeafec9 (patch)
tree8a555e5599f3746831afda210b51fd9404b8670a /src/core
parent8a493df450829eeaacac46243ecfcc99a40e3755 (diff)
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c25
-rw-r--r--src/core/cgroup.h2
2 files changed, 27 insertions, 0 deletions
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);