X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fcgroup-util.c;h=c1c4d409ae5ee6bcc30d5d743473417861dbc6e4;hp=9692a07f56484a2071321fb9371e66cca79543be;hb=f7f628b5db770feb8b18990436baefaec55c460b;hpb=89f7c8465cd1ab37347dd0c15920bce31e8225df diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 9692a07f5..c1c4d409a 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -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; }