chiark / gitweb /
Add function to open temp files in selinux mode
[elogind.git] / src / shared / cgroup-util.c
index 9692a07f56484a2071321fb9371e66cca79543be..c1c4d409ae5ee6bcc30d5d743473417861dbc6e4 100644 (file)
@@ -472,9 +472,7 @@ static int join_path(const char *controller, const char *path, const char *suffi
         if (!t)
                 return -ENOMEM;
 
-        path_kill_slashes(t);
-
-        *fs = t;
+        *fs = path_kill_slashes(t);
         return 0;
 }
 
@@ -509,7 +507,7 @@ static int check_hierarchy(const char *p) {
         assert(p);
 
         /* Check if this controller actually really exists */
-        cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(p));
+        cc = alloca(strlen("/sys/fs/cgroup/") + strlen(p) + 1);
         strcpy(stpcpy(cc, "/sys/fs/cgroup/"), p);
         if (access(cc, F_OK) < 0)
                 return -errno;
@@ -643,7 +641,7 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
         if (pid == 0)
                 pid = getpid();
 
-        snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
+        snprintf(c, sizeof(c), PID_FMT"\n", pid);
 
         return write_string_file(fs, c);
 }
@@ -957,8 +955,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
                         if (!t)
                                 return -ENOMEM;
 
-                        path_kill_slashes(t);
-                        *path = t;
+                        *path = path_kill_slashes(t);
                 }
 
                 if (controller)
@@ -1041,19 +1038,18 @@ int cg_mangle_path(const char *path, char **result) {
         assert(path);
         assert(result);
 
-        /* First check if it already is a filesystem path */
+        /* First, check if it already is a filesystem path */
         if (path_startswith(path, "/sys/fs/cgroup")) {
 
                 t = strdup(path);
                 if (!t)
                         return -ENOMEM;
 
-                path_kill_slashes(t);
-                *result = t;
+                *result = path_kill_slashes(t);
                 return 0;
         }
 
-        /* Otherwise treat it as cg spec */
+        /* Otherwise, treat it as cg spec */
         r = cg_split_spec(path, &c, &p);
         if (r < 0)
                 return r;
@@ -1668,7 +1664,7 @@ int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path,
         return r;
 }
 
-int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to) {
+int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to, cg_migrate_callback_t to_callback, void *userdata) {
         CGroupControllerMask bit = 1;
         const char *n;
         int r;
@@ -1680,8 +1676,17 @@ int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, cons
         }
 
         NULSTR_FOREACH(n, mask_names) {
-                if (supported & bit)
-                        cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, n, to, false, false);
+                if (supported & bit) {
+                        const char *p = NULL;
+
+                        if (to_callback)
+                                p = to_callback(bit, userdata);
+
+                        if (!p)
+                                p = to;
+
+                        cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, n, p, false, false);
+                }
 
                 bit <<= 1;
         }