[systemd-devel] [PATCH] cgroup: Handle error when destroying cgroup

Ross Lagerwall rosslagerwall at gmail.com
Sat Nov 29 07:27:14 PST 2014


If a cgroup fails to be destroyed (most likely because there are still
processes running as part of a service after the main pid exits), don't
free and remove the cgroup unit from the manager.  This fixes a
regression introduced by the cgroup rework in v205 where systemd would
forget about processes still running after the unit becomes inactive.
(This can happen when the main pid exits and KillMode=process or none).
---

Not sure if this is the correct fix but it seems to fix the issue I reported.
When the issue occurs, this notice is visible in the logs:
Nov 28 22:11:32 centi7 systemd[1]: Failed to destroy cgroup /system.slice/tester.service: Device or resource busy

 src/core/cgroup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 70fc925..af04835 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -791,8 +791,10 @@ void unit_destroy_cgroup(Unit *u) {
                 return;
 
         r = cg_trim_everywhere(u->manager->cgroup_supported, u->cgroup_path, !unit_has_name(u, SPECIAL_ROOT_SLICE));
-        if (r < 0)
+        if (r < 0) {
                 log_debug_errno(r, "Failed to destroy cgroup %s: %m", u->cgroup_path);
+                return;
+        }
 
         hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
 
-- 
2.1.2



More information about the systemd-devel mailing list