]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: do 'catchup' for unit cgroup inotify watch files
authorDan Streetman <ddstreet@canonical.com>
Sun, 11 Jul 2021 20:59:27 +0000 (16:59 -0400)
committerDan Streetman <ddstreet@canonical.com>
Thu, 5 Aug 2021 14:35:20 +0000 (10:35 -0400)
While reexec/reload, we drop the inotify watch on cgroup file(s), so
we need to re-check them in case they changed and we missed the event.

Fixes: #20198
src/core/cgroup.c
src/core/cgroup.h
src/core/unit.c

index da821465da249f5b512f29a1586e7d13dc5cc067..bbeb5b2f50b98bc4899296f0038547a11d333aeb 100644 (file)
@@ -3031,6 +3031,9 @@ static int unit_check_cgroup_events(Unit *u) {
 
         assert(u);
 
+        if (!u->cgroup_path)
+                return 0;
+
         r = cg_get_keyed_attribute_graceful(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "cgroup.events",
                                             STRV_MAKE("populated", "frozen"), values);
         if (r < 0)
@@ -3863,6 +3866,21 @@ void unit_invalidate_cgroup_bpf(Unit *u) {
         }
 }
 
+void unit_cgroup_catchup(Unit *u) {
+        assert(u);
+
+        if (!UNIT_HAS_CGROUP_CONTEXT(u))
+                return;
+
+        /* We dropped the inotify watch during reexec/reload, so we need to
+         * check these as they may have changed.
+         * Note that (currently) the kernel doesn't actually update cgroup
+         * file modification times, so we can't just serialize and then check
+         * the mtime for file(s) we are interested in. */
+        (void) unit_check_cgroup_events(u);
+        unit_add_to_cgroup_oom_queue(u);
+}
+
 bool unit_cgroup_delegate(Unit *u) {
         CGroupContext *c;
 
index ea929368cbd4d409a6dae3136ddc8d5d5d612a6c..3f8cad899de56ff398a2684c4e3952a21778793d 100644 (file)
@@ -313,6 +313,8 @@ void manager_invalidate_startup_units(Manager *m);
 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
 
+void unit_cgroup_catchup(Unit *u);
+
 bool unit_cgroup_delegate(Unit *u);
 
 int compare_job_priority(const void *a, const void *b);
index 8ce94ccb75e641c216e936dde611fcedad15781e..50a188203428e4fcab107d19d484c7ec73fa903e 100644 (file)
@@ -3611,6 +3611,8 @@ void unit_catchup(Unit *u) {
 
         if (UNIT_VTABLE(u)->catchup)
                 UNIT_VTABLE(u)->catchup(u);
+
+        unit_cgroup_catchup(u);
 }
 
 static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_masked) {