1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include <sys/types.h>
32 #include "cgroup-util.h"
37 #include "path-util.h"
39 #include "unit-name.h"
44 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
45 _cleanup_free_ char *fs = NULL;
51 r = cg_get_path(controller, path, "cgroup.procs", &fs);
63 int cg_read_pid(FILE *f, pid_t *_pid) {
66 /* Note that the cgroup.procs might contain duplicates! See
67 * cgroups.txt for details. */
73 if (fscanf(f, "%lu", &ul) != 1) {
78 return errno ? -errno : -EIO;
88 int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
89 _cleanup_free_ char *fs = NULL;
95 /* This is not recursive! */
97 r = cg_get_path(controller, path, NULL, &fs);
109 int cg_read_subgroup(DIR *d, char **fn) {
115 FOREACH_DIRENT(de, d, return -errno) {
118 if (de->d_type != DT_DIR)
121 if (streq(de->d_name, ".") ||
122 streq(de->d_name, ".."))
125 b = strdup(de->d_name);
136 int cg_rmdir(const char *controller, const char *path) {
137 _cleanup_free_ char *p = NULL;
140 r = cg_get_path(controller, path, NULL, &p);
145 if (r < 0 && errno != ENOENT)
151 int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s) {
152 _cleanup_set_free_ Set *allocated_set = NULL;
159 /* This goes through the tasks list and kills them all. This
160 * is repeated until no further processes are added to the
161 * tasks list, to properly handle forking processes */
164 s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
172 _cleanup_fclose_ FILE *f = NULL;
176 r = cg_enumerate_processes(controller, path, &f);
178 if (ret >= 0 && r != -ENOENT)
184 while ((r = cg_read_pid(f, &pid)) > 0) {
186 if (ignore_self && pid == my_pid)
189 if (set_get(s, LONG_TO_PTR(pid)) == LONG_TO_PTR(pid))
192 /* If we haven't killed this process yet, kill
194 if (kill(pid, sig) < 0) {
195 if (ret >= 0 && errno != ESRCH)
207 r = set_put(s, LONG_TO_PTR(pid));
223 /* To avoid racing against processes which fork
224 * quicker than we can kill them we repeat this until
225 * no new pids need to be killed. */
232 int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool rem, Set *s) {
233 _cleanup_set_free_ Set *allocated_set = NULL;
234 _cleanup_closedir_ DIR *d = NULL;
242 s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
247 ret = cg_kill(controller, path, sig, sigcont, ignore_self, s);
249 r = cg_enumerate_subgroups(controller, path, &d);
251 if (ret >= 0 && r != -ENOENT)
257 while ((r = cg_read_subgroup(d, &fn)) > 0) {
258 _cleanup_free_ char *p = NULL;
260 p = strjoin(path, "/", fn, NULL);
265 r = cg_kill_recursive(controller, p, sig, sigcont, ignore_self, rem, s);
266 if (ret >= 0 && r != 0)
270 if (ret >= 0 && r < 0)
274 r = cg_rmdir(controller, path);
275 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
282 int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self) {
284 _cleanup_set_free_ Set *s = NULL;
293 s = set_new(trivial_hash_func, trivial_compare_func);
300 _cleanup_fclose_ FILE *f = NULL;
304 r = cg_enumerate_processes(cfrom, pfrom, &f);
306 if (ret >= 0 && r != -ENOENT)
312 while ((r = cg_read_pid(f, &pid)) > 0) {
314 /* This might do weird stuff if we aren't a
315 * single-threaded program. However, we
316 * luckily know we are not */
317 if (ignore_self && pid == my_pid)
320 if (set_get(s, LONG_TO_PTR(pid)) == LONG_TO_PTR(pid))
323 r = cg_attach(cto, pto, pid);
325 if (ret >= 0 && r != -ESRCH)
332 r = set_put(s, LONG_TO_PTR(pid));
352 int cg_migrate_recursive(
360 _cleanup_closedir_ DIR *d = NULL;
369 ret = cg_migrate(cfrom, pfrom, cto, pto, ignore_self);
371 r = cg_enumerate_subgroups(cfrom, pfrom, &d);
373 if (ret >= 0 && r != -ENOENT)
379 while ((r = cg_read_subgroup(d, &fn)) > 0) {
380 _cleanup_free_ char *p = NULL;
382 p = strjoin(pfrom, "/", fn, NULL);
391 r = cg_migrate_recursive(cfrom, p, cto, pto, ignore_self, rem);
392 if (r != 0 && ret >= 0)
396 if (r < 0 && ret >= 0)
400 r = cg_rmdir(cfrom, pfrom);
401 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
408 int cg_migrate_recursive_fallback(
423 r = cg_migrate_recursive(cfrom, pfrom, cto, pto, ignore_self, rem);
425 char prefix[strlen(pto) + 1];
427 /* This didn't work? Then let's try all prefixes of the destination */
429 PATH_FOREACH_PREFIX(prefix, pto) {
430 r = cg_migrate_recursive(cfrom, pfrom, cto, prefix, ignore_self, rem);
439 static const char *normalize_controller(const char *controller) {
443 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
445 else if (startswith(controller, "name="))
446 return controller + 5;
451 static int join_path(const char *controller, const char *path, const char *suffix, char **fs) {
454 if (!isempty(controller)) {
455 if (!isempty(path) && !isempty(suffix))
456 t = strjoin("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL);
457 else if (!isempty(path))
458 t = strjoin("/sys/fs/cgroup/", controller, "/", path, NULL);
459 else if (!isempty(suffix))
460 t = strjoin("/sys/fs/cgroup/", controller, "/", suffix, NULL);
462 t = strappend("/sys/fs/cgroup/", controller);
464 if (!isempty(path) && !isempty(suffix))
465 t = strjoin(path, "/", suffix, NULL);
466 else if (!isempty(path))
475 *fs = path_kill_slashes(t);
479 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
481 static thread_local bool good = false;
485 if (controller && !cg_controller_is_valid(controller, true))
488 if (_unlikely_(!good)) {
491 r = path_is_mount_point("/sys/fs/cgroup", false);
493 return r < 0 ? r : -ENOENT;
495 /* Cache this to save a few stat()s */
499 p = controller ? normalize_controller(controller) : NULL;
501 return join_path(p, path, suffix, fs);
504 static int check_hierarchy(const char *p) {
509 /* Check if this controller actually really exists */
510 cc = alloca(strlen("/sys/fs/cgroup/") + strlen(p) + 1);
511 strcpy(stpcpy(cc, "/sys/fs/cgroup/"), p);
512 if (access(cc, F_OK) < 0)
518 int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) {
524 if (!cg_controller_is_valid(controller, true))
527 /* Normalize the controller syntax */
528 p = normalize_controller(controller);
530 /* Check if this controller actually really exists */
531 r = check_hierarchy(p);
535 return join_path(p, path, suffix, fs);
538 static int trim_cb(const char *path, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
543 if (typeflag != FTW_DP)
546 if (ftwbuf->level < 1)
553 int cg_trim(const char *controller, const char *path, bool delete_root) {
554 _cleanup_free_ char *fs = NULL;
559 r = cg_get_path(controller, path, NULL, &fs);
564 if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0)
565 r = errno ? -errno : -EIO;
568 if (rmdir(fs) < 0 && errno != ENOENT)
575 int cg_delete(const char *controller, const char *path) {
576 _cleanup_free_ char *parent = NULL;
581 r = path_get_parent(path, &parent);
585 r = cg_migrate_recursive(controller, path, controller, parent, false, true);
586 return r == -ENOENT ? 0 : r;
589 int cg_create(const char *controller, const char *path) {
590 _cleanup_free_ char *fs = NULL;
593 r = cg_get_path_and_check(controller, path, NULL, &fs);
597 r = mkdir_parents(fs, 0755);
601 if (mkdir(fs, 0755) < 0) {
612 int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
617 r = cg_create(controller, path);
621 q = cg_attach(controller, path, pid);
625 /* This does not remove the cgroup on failure */
629 int cg_attach(const char *controller, const char *path, pid_t pid) {
630 _cleanup_free_ char *fs = NULL;
631 char c[DECIMAL_STR_MAX(pid_t) + 2];
637 r = cg_get_path_and_check(controller, path, "cgroup.procs", &fs);
644 snprintf(c, sizeof(c), PID_FMT"\n", pid);
646 return write_string_file_no_create(fs, c);
649 int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
656 r = cg_attach(controller, path, pid);
658 char prefix[strlen(path) + 1];
660 /* This didn't work? Then let's try all prefixes of
663 PATH_FOREACH_PREFIX(prefix, path) {
664 r = cg_attach(controller, prefix, pid);
673 int cg_set_group_access(
674 const char *controller,
680 _cleanup_free_ char *fs = NULL;
685 if (mode != (mode_t) -1)
688 r = cg_get_path(controller, path, NULL, &fs);
692 return chmod_and_chown(fs, mode, uid, gid);
695 int cg_set_task_access(
696 const char *controller,
702 _cleanup_free_ char *fs = NULL, *procs = NULL;
707 if (mode == (mode_t) -1 && uid == (uid_t) -1 && gid == (gid_t) -1)
710 if (mode != (mode_t) -1)
713 r = cg_get_path(controller, path, "cgroup.procs", &fs);
717 r = chmod_and_chown(fs, mode, uid, gid);
721 /* Compatibility, Always keep values for "tasks" in sync with
723 r = cg_get_path(controller, path, "tasks", &procs);
727 return chmod_and_chown(procs, mode, uid, gid);
730 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
731 _cleanup_fclose_ FILE *f = NULL;
740 if (!cg_controller_is_valid(controller, true))
743 controller = normalize_controller(controller);
745 controller = SYSTEMD_CGROUP_CONTROLLER;
747 fs = procfs_file_alloca(pid, "cgroup");
751 return errno == ENOENT ? -ESRCH : -errno;
753 cs = strlen(controller);
755 FOREACH_LINE(line, f, return -errno) {
758 const char *word, *state;
763 l = strchr(line, ':');
774 FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
776 if (k == cs && memcmp(word, controller, cs) == 0) {
782 memcmp(word, "name=", 5) == 0 &&
783 memcmp(word+5, controller, cs) == 0) {
803 int cg_install_release_agent(const char *controller, const char *agent) {
804 _cleanup_free_ char *fs = NULL, *contents = NULL;
810 r = cg_get_path(controller, NULL, "release_agent", &fs);
814 r = read_one_line_file(fs, &contents);
818 sc = strstrip(contents);
820 r = write_string_file_no_create(fs, agent);
823 } else if (!streq(sc, agent))
828 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
834 r = read_one_line_file(fs, &contents);
838 sc = strstrip(contents);
839 if (streq(sc, "0")) {
840 r = write_string_file_no_create(fs, "1");
853 int cg_uninstall_release_agent(const char *controller) {
854 _cleanup_free_ char *fs = NULL;
857 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
861 r = write_string_file_no_create(fs, "0");
868 r = cg_get_path(controller, NULL, "release_agent", &fs);
872 r = write_string_file_no_create(fs, "");
879 int cg_is_empty(const char *controller, const char *path, bool ignore_self) {
880 _cleanup_fclose_ FILE *f = NULL;
881 pid_t pid = 0, self_pid;
887 r = cg_enumerate_processes(controller, path, &f);
889 return r == -ENOENT ? 1 : r;
893 while ((r = cg_read_pid(f, &pid)) > 0) {
895 if (ignore_self && pid == self_pid)
908 int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self) {
909 _cleanup_closedir_ DIR *d = NULL;
915 r = cg_is_empty(controller, path, ignore_self);
919 r = cg_enumerate_subgroups(controller, path, &d);
921 return r == -ENOENT ? 1 : r;
923 while ((r = cg_read_subgroup(d, &fn)) > 0) {
924 _cleanup_free_ char *p = NULL;
926 p = strjoin(path, "/", fn, NULL);
931 r = cg_is_empty_recursive(controller, p, ignore_self);
942 int cg_split_spec(const char *spec, char **controller, char **path) {
944 char *t = NULL, *u = NULL;
945 _cleanup_free_ char *v = NULL;
950 if (!path_is_safe(spec))
958 *path = path_kill_slashes(t);
967 e = strchr(spec, ':');
969 if (!cg_controller_is_valid(spec, true))
973 t = strdup(normalize_controller(spec));
986 v = strndup(spec, e-spec);
989 t = strdup(normalize_controller(v));
992 if (!cg_controller_is_valid(t, true)) {
997 if (streq(e+1, "")) {
1010 if (!path_is_safe(u) ||
1011 !path_is_absolute(u)) {
1017 path_kill_slashes(u);
1033 int cg_mangle_path(const char *path, char **result) {
1034 _cleanup_free_ char *c = NULL, *p = NULL;
1041 /* First, check if it already is a filesystem path */
1042 if (path_startswith(path, "/sys/fs/cgroup")) {
1048 *result = path_kill_slashes(t);
1052 /* Otherwise, treat it as cg spec */
1053 r = cg_split_spec(path, &c, &p);
1057 return cg_get_path(c ? c : SYSTEMD_CGROUP_CONTROLLER, p ? p : "/", NULL, result);
1060 int cg_get_root_path(char **path) {
1066 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 1, &p);
1070 e = endswith(p, "/" SPECIAL_SYSTEM_SLICE);
1078 int cg_shift_path(const char *cgroup, const char *root, const char **shifted) {
1079 _cleanup_free_ char *rt = NULL;
1087 /* If the root was specified let's use that, otherwise
1088 * let's determine it from PID 1 */
1090 r = cg_get_root_path(&rt);
1097 p = path_startswith(cgroup, root);
1106 int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
1107 _cleanup_free_ char *raw = NULL;
1114 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &raw);
1118 r = cg_shift_path(raw, root, &c);
1138 int cg_path_decode_unit(const char *cgroup, char **unit){
1144 e = strchrnul(cgroup, '/');
1145 c = strndupa(cgroup, e - cgroup);
1148 if (!unit_name_is_valid(c, TEMPLATE_INVALID))
1159 static const char *skip_slices(const char *p) {
1160 /* Skips over all slice assignments */
1165 p += strspn(p, "/");
1167 n = strcspn(p, "/");
1168 if (n <= 6 || memcmp(p + n - 6, ".slice", 6) != 0)
1175 int cg_path_get_unit(const char *path, char **unit) {
1181 e = skip_slices(path);
1183 return cg_path_decode_unit(e, unit);
1186 int cg_pid_get_unit(pid_t pid, char **unit) {
1187 _cleanup_free_ char *cgroup = NULL;
1192 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1196 return cg_path_get_unit(cgroup, unit);
1200 * Skip session-*.scope, but require it to be there.
1202 static const char *skip_session(const char *p) {
1207 p += strspn(p, "/");
1209 n = strcspn(p, "/");
1210 if (n < strlen("session-x.scope") || memcmp(p, "session-", 8) != 0 || memcmp(p + n - 6, ".scope", 6) != 0)
1214 p += strspn(p, "/");
1220 * Skip user@*.service, but require it to be there.
1222 static const char *skip_user_manager(const char *p) {
1227 p += strspn(p, "/");
1229 n = strcspn(p, "/");
1230 if (n < strlen("user@x.service") || memcmp(p, "user@", 5) != 0 || memcmp(p + n - 8, ".service", 8) != 0)
1234 p += strspn(p, "/");
1239 int cg_path_get_user_unit(const char *path, char **unit) {
1245 /* We always have to parse the path from the beginning as unit
1246 * cgroups might have arbitrary child cgroups and we shouldn't get
1247 * confused by those */
1249 /* Skip slices, if there are any */
1250 e = skip_slices(path);
1252 /* Skip the session scope... */
1253 t = skip_session(e);
1255 /* ... and skip more slices if there's one */
1258 /* ... or require a user manager unit to be there */
1259 e = skip_user_manager(e);
1264 return cg_path_decode_unit(e, unit);
1267 int cg_pid_get_user_unit(pid_t pid, char **unit) {
1268 _cleanup_free_ char *cgroup = NULL;
1273 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1277 return cg_path_get_user_unit(cgroup, unit);
1280 int cg_path_get_machine_name(const char *path, char **machine) {
1281 _cleanup_free_ char *u = NULL, *sl = NULL;
1284 r = cg_path_get_unit(path, &u);
1288 sl = strjoin("/run/systemd/machines/unit:", u, NULL);
1292 return readlink_malloc(sl, machine);
1295 int cg_pid_get_machine_name(pid_t pid, char **machine) {
1296 _cleanup_free_ char *cgroup = NULL;
1301 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1305 return cg_path_get_machine_name(cgroup, machine);
1308 int cg_path_get_session(const char *path, char **session) {
1309 const char *e, *n, *x;
1315 /* Skip slices, if there are any */
1316 e = skip_slices(path);
1318 n = strchrnul(e, '/');
1322 s = strndupa(e, n - e);
1325 x = startswith(s, "session-");
1328 if (!endswith(x, ".scope"))
1338 r = strndup(x, l - 6);
1348 int cg_pid_get_session(pid_t pid, char **session) {
1349 _cleanup_free_ char *cgroup = NULL;
1352 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1356 return cg_path_get_session(cgroup, session);
1359 int cg_path_get_owner_uid(const char *path, uid_t *uid) {
1360 _cleanup_free_ char *slice = NULL;
1361 const char *start, *end;
1368 r = cg_path_get_slice(path, &slice);
1372 start = startswith(slice, "user-");
1375 end = endswith(slice, ".slice");
1379 s = strndupa(start, end - start);
1383 if (parse_uid(s, &u) < 0)
1392 int cg_pid_get_owner_uid(pid_t pid, uid_t *uid) {
1393 _cleanup_free_ char *cgroup = NULL;
1396 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1400 return cg_path_get_owner_uid(cgroup, uid);
1403 int cg_path_get_slice(const char *p, char **slice) {
1404 const char *e = NULL;
1413 p += strspn(p, "/");
1415 n = strcspn(p, "/");
1416 if (n <= 6 || memcmp(p + n - 6, ".slice", 6) != 0) {
1437 int cg_pid_get_slice(pid_t pid, char **slice) {
1438 _cleanup_free_ char *cgroup = NULL;
1443 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1447 return cg_path_get_slice(cgroup, slice);
1450 char *cg_escape(const char *p) {
1451 bool need_prefix = false;
1453 /* This implements very minimal escaping for names to be used
1454 * as file names in the cgroup tree: any name which might
1455 * conflict with a kernel name or is prefixed with '_' is
1456 * prefixed with a '_'. That way, when reading cgroup names it
1457 * is sufficient to remove a single prefixing underscore if
1460 /* The return value of this function (unlike cg_unescape())
1466 streq(p, "notify_on_release") ||
1467 streq(p, "release_agent") ||
1473 dot = strrchr(p, '.');
1476 if (dot - p == 6 && memcmp(p, "cgroup", 6) == 0)
1481 n = strndupa(p, dot - p);
1483 if (check_hierarchy(n) >= 0)
1490 return strappend("_", p);
1495 char *cg_unescape(const char *p) {
1498 /* The return value of this function (unlike cg_escape())
1499 * doesn't need free()! */
1507 #define CONTROLLER_VALID \
1511 bool cg_controller_is_valid(const char *p, bool allow_named) {
1518 s = startswith(p, "name=");
1523 if (*p == 0 || *p == '_')
1526 for (t = p; *t; t++)
1527 if (!strchr(CONTROLLER_VALID, *t))
1530 if (t - p > FILENAME_MAX)
1536 int cg_slice_to_path(const char *unit, char **ret) {
1537 _cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
1543 if (!unit_name_is_valid(unit, TEMPLATE_INVALID))
1546 if (!endswith(unit, ".slice"))
1549 p = unit_name_to_prefix(unit);
1553 dash = strchr(p, '-');
1555 _cleanup_free_ char *escaped = NULL;
1556 char n[dash - p + sizeof(".slice")];
1558 strcpy(stpncpy(n, p, dash - p), ".slice");
1560 if (!unit_name_is_valid(n, TEMPLATE_INVALID))
1563 escaped = cg_escape(n);
1567 if (!strextend(&s, escaped, "/", NULL))
1570 dash = strchr(dash+1, '-');
1573 e = cg_escape(unit);
1577 if (!strextend(&s, e, NULL))
1586 int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
1587 _cleanup_free_ char *p = NULL;
1590 r = cg_get_path(controller, path, attribute, &p);
1594 return write_string_file_no_create(p, value);
1597 static const char mask_names[] =
1604 int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path) {
1605 CGroupControllerMask bit = 1;
1609 /* This one will create a cgroup in our private tree, but also
1610 * duplicate it in the trees specified in mask, and remove it
1613 /* First create the cgroup in our own hierarchy. */
1614 r = cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
1618 /* Then, do the same in the other hierarchies */
1619 NULSTR_FOREACH(n, mask_names) {
1622 else if (supported & bit)
1623 cg_trim(n, path, true);
1631 int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid) {
1632 CGroupControllerMask bit = 1;
1636 r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
1640 NULSTR_FOREACH(n, mask_names) {
1641 if (supported & bit)
1642 cg_attach_fallback(n, path, pid);
1650 int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids) {
1655 SET_FOREACH(pidp, pids, i) {
1656 pid_t pid = PTR_TO_LONG(pidp);
1659 q = cg_attach_everywhere(supported, path, pid);
1667 int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to, cg_migrate_callback_t to_callback, void *userdata) {
1668 CGroupControllerMask bit = 1;
1672 if (!path_equal(from, to)) {
1673 r = cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, from, SYSTEMD_CGROUP_CONTROLLER, to, false, true);
1678 NULSTR_FOREACH(n, mask_names) {
1679 if (supported & bit) {
1680 const char *p = NULL;
1683 p = to_callback(bit, userdata);
1688 cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, n, p, false, false);
1697 int cg_trim_everywhere(CGroupControllerMask supported, const char *path, bool delete_root) {
1698 CGroupControllerMask bit = 1;
1702 r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
1706 NULSTR_FOREACH(n, mask_names) {
1707 if (supported & bit)
1708 cg_trim(n, path, delete_root);
1716 CGroupControllerMask cg_mask_supported(void) {
1717 CGroupControllerMask bit = 1, mask = 0;
1720 NULSTR_FOREACH(n, mask_names) {
1721 if (check_hierarchy(n) >= 0)