chiark / gitweb /
logind: properly clean up user cgroups when they run empty
[elogind.git] / src / login / logind-user.c
index b971845e1440a416471e897c1ef9010462b7cd16..8bd773086e11a6653a03122ee328c6b28b25517e 100644 (file)
@@ -75,6 +75,8 @@ void user_free(User *u) {
         while (u->sessions)
                 session_free(u->sessions);
 
         while (u->sessions)
                 session_free(u->sessions);
 
+        if (u->cgroup_path)
+                hashmap_remove(u->manager->user_cgroups, u->cgroup_path);
         free(u->cgroup_path);
 
         free(u->service);
         free(u->cgroup_path);
 
         free(u->service);
@@ -313,6 +315,8 @@ static int user_create_cgroup(User *u) {
                         log_warning("Failed to create cgroup %s:%s: %s", *k, p, strerror(-r));
         }
 
                         log_warning("Failed to create cgroup %s:%s: %s", *k, p, strerror(-r));
         }
 
+        hashmap_put(u->manager->user_cgroups, u->cgroup_path, u);
+
         return 0;
 }
 
         return 0;
 }
 
@@ -417,6 +421,8 @@ static int user_terminate_cgroup(User *u) {
         STRV_FOREACH(k, u->manager->controllers)
                 cg_trim(*k, u->cgroup_path, true);
 
         STRV_FOREACH(k, u->manager->controllers)
                 cg_trim(*k, u->cgroup_path, true);
 
+        hashmap_remove(u->manager->user_cgroups, u->cgroup_path);
+
         free(u->cgroup_path);
         u->cgroup_path = NULL;
 
         free(u->cgroup_path);
         u->cgroup_path = NULL;