]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: whenever we migrate a PID to a unit, explicitly drop unit from empty notifica...
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Mar 2025 15:54:27 +0000 (16:54 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 8 Apr 2025 19:52:11 +0000 (20:52 +0100)
A unit might be pending in the empty queue still when we add a PID to
the cgroup. At that point, let's explicitly remove the unit from that
queue.

Fixes: #36781
(cherry picked from commit bb160976b0d2d84d3b23149ce6a4d5b89a665643)
(cherry picked from commit 13b011f0e84bd30d524a10e0dd839b508b8e0011)

src/core/cgroup.c

index 09c6d72d7b87eb725343cd1af9197a481c6fa815..33dfee96f9f7a08fdaa5961a136693fbbe5d08d4 100644 (file)
@@ -54,6 +54,8 @@
  * out specific attributes from us. */
 #define LOG_LEVEL_CGROUP_WRITE(r) (IN_SET(abs(r), ENOENT, EROFS, EACCES, EPERM) ? LOG_DEBUG : LOG_WARNING)
 
+static void unit_remove_from_cgroup_empty_queue(Unit *u);
+
 uint64_t cgroup_tasks_max_resolve(const CGroupTasksMax *tasks_max) {
         if (tasks_max->scale == 0)
                 return tasks_max->value;
@@ -3065,6 +3067,10 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
                                 else {
                                         if (ret >= 0)
                                                 ret++; /* Count successful additions */
+
+                                        /* the cgroup is definitely not empty now, in case the unit was in
+                                         * the cgroup empty queue, drop it from there */
+                                        unit_remove_from_cgroup_empty_queue(u);
                                         continue; /* When the bus thing worked via the bus we are fully done for this PID. */
                                 }
                         }
@@ -3073,8 +3079,10 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
                                 ret = r; /* Remember first error */
 
                         continue;
-                } else if (ret >= 0)
+                } else if (ret >= 0) {
+                        unit_remove_from_cgroup_empty_queue(u);
                         ret++; /* Count successful additions */
+                }
 
                 r = cg_all_unified();
                 if (r < 0)