chiark / gitweb /
cgroup: don't trim a cgroup we create, we might just take it over from somebody else
[elogind.git] / src / cgroup.c
index ca19a4fd4768ef55910e64f5337e0184402d6ab3..4aa01f18981b5c7a84e7ba2b66c78855201f344d 100644 (file)
@@ -46,9 +46,6 @@ int cgroup_bonding_realize(CGroupBonding *b) {
 
         b->realized = true;
 
-        if (b->ours)
-                cg_trim(b->controller, b->path, false);
-
         return 0;
 }
 
@@ -63,7 +60,7 @@ int cgroup_bonding_realize_list(CGroupBonding *first) {
         return 0;
 }
 
-void cgroup_bonding_free(CGroupBonding *b) {
+void cgroup_bonding_free(CGroupBonding *b, bool remove_or_trim) {
         assert(b);
 
         if (b->unit) {
@@ -82,7 +79,7 @@ void cgroup_bonding_free(CGroupBonding *b) {
                 }
         }
 
-        if (b->realized && b->ours) {
+        if (b->realized && b->ours && remove_or_trim) {
 
                 if (cgroup_bonding_is_empty(b) > 0)
                         cg_delete(b->controller, b->path);
@@ -95,11 +92,11 @@ void cgroup_bonding_free(CGroupBonding *b) {
         free(b);
 }
 
-void cgroup_bonding_free_list(CGroupBonding *first) {
+void cgroup_bonding_free_list(CGroupBonding *first, bool remove_or_trim) {
         CGroupBonding *b, *n;
 
         LIST_FOREACH_SAFE(by_unit, b, n, first)
-                cgroup_bonding_free(b);
+                cgroup_bonding_free(b, remove_or_trim);
 }
 
 void cgroup_bonding_trim(CGroupBonding *b, bool delete_root) {
@@ -140,12 +137,56 @@ int cgroup_bonding_install_list(CGroupBonding *first, pid_t pid) {
         return 0;
 }
 
+int cgroup_bonding_set_group_access(CGroupBonding *b, mode_t mode, uid_t uid, gid_t gid) {
+        assert(b);
+
+        if (!b->realized)
+                return -EINVAL;
+
+        return cg_set_group_access(b->controller, b->path, mode, uid, gid);
+}
+
+int cgroup_bonding_set_group_access_list(CGroupBonding *first, mode_t mode, uid_t uid, gid_t gid) {
+        CGroupBonding *b;
+        int r;
+
+        LIST_FOREACH(by_unit, b, first) {
+                r = cgroup_bonding_set_group_access(b, mode, uid, gid);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
+int cgroup_bonding_set_task_access(CGroupBonding *b, mode_t mode, uid_t uid, gid_t gid) {
+        assert(b);
+
+        if (!b->realized)
+                return -EINVAL;
+
+        return cg_set_task_access(b->controller, b->path, mode, uid, gid);
+}
+
+int cgroup_bonding_set_task_access_list(CGroupBonding *first, mode_t mode, uid_t uid, gid_t gid) {
+        CGroupBonding *b;
+        int r;
+
+        LIST_FOREACH(by_unit, b, first) {
+                r = cgroup_bonding_set_task_access(b, mode, uid, gid);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
 int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, Set *s) {
         assert(b);
         assert(sig >= 0);
 
         /* Don't kill cgroups that aren't ours */
-        if (!b->realized || !b->ours)
+        if (!b->ours)
                 return 0;
 
         return cg_kill_recursive(b->controller, b->path, sig, sigcont, true, false, s);