[systemd-devel] [PATCH] cgroups: chown user slices

Marc-Antoine Perennou Marc-Antoine at Perennou.com
Fri Jul 5 16:16:45 PDT 2013


When creating the cgroup hierarchy for a user slice,
chown this slice to the user uid.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
---
 src/shared/cgroup-label.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/shared/cgroup-label.c b/src/shared/cgroup-label.c
index 574a7be..1891c9a 100644
--- a/src/shared/cgroup-label.c
+++ b/src/shared/cgroup-label.c
@@ -41,6 +41,7 @@
 
 int cg_create(const char *controller, const char *path) {
         _cleanup_free_ char *fs = NULL;
+        uid_t uid = (uid_t) -1;
         int r;
 
         r = cg_get_path_and_check(controller, path, NULL, &fs);
@@ -59,6 +60,13 @@ int cg_create(const char *controller, const char *path) {
                 return -errno;
         }
 
+        r = cg_path_get_owner_uid(path, &uid);
+        if (r < 0 && r != -ENOENT)
+            return r;
+
+        if (uid != (uid_t) -1)
+            chown(fs, uid, (gid_t) -1);
+
         return 1;
 }
 
-- 
1.8.3.2



More information about the systemd-devel mailing list