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"
43 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
44 _cleanup_free_ char *fs = NULL;
50 r = cg_get_path(controller, path, "cgroup.procs", &fs);
62 int cg_read_pid(FILE *f, pid_t *_pid) {
65 /* Note that the cgroup.procs might contain duplicates! See
66 * cgroups.txt for details. */
72 if (fscanf(f, "%lu", &ul) != 1) {
77 return errno ? -errno : -EIO;
87 int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
88 _cleanup_free_ char *fs = NULL;
94 /* This is not recursive! */
96 r = cg_get_path(controller, path, NULL, &fs);
108 int cg_read_subgroup(DIR *d, char **fn) {
114 FOREACH_DIRENT(de, d, return -errno) {
117 if (de->d_type != DT_DIR)
120 if (streq(de->d_name, ".") ||
121 streq(de->d_name, ".."))
124 b = strdup(de->d_name);
135 int cg_rmdir(const char *controller, const char *path) {
136 _cleanup_free_ char *p = NULL;
139 r = cg_get_path(controller, path, NULL, &p);
144 if (r < 0 && errno != ENOENT)
150 int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s) {
151 _cleanup_set_free_ Set *allocated_set = NULL;
158 /* This goes through the tasks list and kills them all. This
159 * is repeated until no further processes are added to the
160 * tasks list, to properly handle forking processes */
163 s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
171 _cleanup_fclose_ FILE *f = NULL;
175 r = cg_enumerate_processes(controller, path, &f);
177 if (ret >= 0 && r != -ENOENT)
183 while ((r = cg_read_pid(f, &pid)) > 0) {
185 if (ignore_self && pid == my_pid)
188 if (set_get(s, LONG_TO_PTR(pid)) == LONG_TO_PTR(pid))
191 /* If we haven't killed this process yet, kill
193 if (kill(pid, sig) < 0) {
194 if (ret >= 0 && errno != ESRCH)
196 } else if (ret == 0) {
206 r = set_put(s, LONG_TO_PTR(pid));
222 /* To avoid racing against processes which fork
223 * quicker than we can kill them we repeat this until
224 * no new pids need to be killed. */
231 int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool rem, Set *s) {
232 _cleanup_set_free_ Set *allocated_set = NULL;
233 _cleanup_closedir_ DIR *d = NULL;
241 s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
246 ret = cg_kill(controller, path, sig, sigcont, ignore_self, s);
248 r = cg_enumerate_subgroups(controller, path, &d);
250 if (ret >= 0 && r != -ENOENT)
256 while ((r = cg_read_subgroup(d, &fn)) > 0) {
257 _cleanup_free_ char *p = NULL;
259 p = strjoin(path, "/", fn, NULL);
264 r = cg_kill_recursive(controller, p, sig, sigcont, ignore_self, rem, s);
265 if (ret >= 0 && r != 0)
269 if (ret >= 0 && r < 0)
273 r = cg_rmdir(controller, path);
274 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
281 int cg_kill_recursive_and_wait(const char *controller, const char *path, bool rem) {
286 /* This safely kills all processes; first it sends a SIGTERM,
287 * then checks 8 times after 200ms whether the group is now
288 * empty, then kills everything that is left with SIGKILL and
289 * finally checks 5 times after 200ms each whether the group
290 * is finally empty. */
292 for (i = 0; i < 15; i++) {
302 r = cg_kill_recursive(controller, path, sig, true, true, rem, NULL);
306 usleep(200 * USEC_PER_MSEC);
312 int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self) {
314 _cleanup_set_free_ Set *s = NULL;
323 s = set_new(trivial_hash_func, trivial_compare_func);
330 _cleanup_fclose_ FILE *f = NULL;
334 r = cg_enumerate_processes(cfrom, pfrom, &f);
336 if (ret >= 0 && r != -ENOENT)
342 while ((r = cg_read_pid(f, &pid)) > 0) {
344 /* This might do weird stuff if we aren't a
345 * single-threaded program. However, we
346 * luckily know we are not */
347 if (ignore_self && pid == my_pid)
350 if (set_get(s, LONG_TO_PTR(pid)) == LONG_TO_PTR(pid))
353 r = cg_attach(cto, pto, pid);
355 if (ret >= 0 && r != -ESRCH)
362 r = set_put(s, LONG_TO_PTR(pid));
382 int cg_migrate_recursive(
390 _cleanup_closedir_ DIR *d = NULL;
399 ret = cg_migrate(cfrom, pfrom, cto, pto, ignore_self);
401 r = cg_enumerate_subgroups(cfrom, pfrom, &d);
403 if (ret >= 0 && r != -ENOENT)
409 while ((r = cg_read_subgroup(d, &fn)) > 0) {
410 _cleanup_free_ char *p = NULL;
412 p = strjoin(pfrom, "/", fn, NULL);
421 r = cg_migrate_recursive(cfrom, p, cto, pto, ignore_self, rem);
422 if (r != 0 && ret >= 0)
426 if (r < 0 && ret >= 0)
430 r = cg_rmdir(cfrom, pfrom);
431 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
438 int cg_migrate_recursive_fallback(
453 r = cg_migrate_recursive(cfrom, pfrom, cto, pto, ignore_self, rem);
455 char prefix[strlen(pto) + 1];
457 /* This didn't work? Then let's try all prefixes of the destination */
459 PATH_FOREACH_PREFIX(prefix, pto) {
460 r = cg_migrate_recursive(cfrom, pfrom, cto, prefix, ignore_self, rem);
469 static const char *normalize_controller(const char *controller) {
473 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
475 else if (startswith(controller, "name="))
476 return controller + 5;
481 static int join_path(const char *controller, const char *path, const char *suffix, char **fs) {
484 if (!isempty(controller)) {
485 if (!isempty(path) && !isempty(suffix))
486 t = strjoin("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL);
487 else if (!isempty(path))
488 t = strjoin("/sys/fs/cgroup/", controller, "/", path, NULL);
489 else if (!isempty(suffix))
490 t = strjoin("/sys/fs/cgroup/", controller, "/", suffix, NULL);
492 t = strappend("/sys/fs/cgroup/", controller);
494 if (!isempty(path) && !isempty(suffix))
495 t = strjoin(path, "/", suffix, NULL);
496 else if (!isempty(path))
505 path_kill_slashes(t);
511 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
513 static __thread bool good = false;
517 if (controller && !cg_controller_is_valid(controller, true))
520 if (_unlikely_(!good)) {
523 r = path_is_mount_point("/sys/fs/cgroup", false);
525 return r < 0 ? r : -ENOENT;
527 /* Cache this to save a few stat()s */
531 p = controller ? normalize_controller(controller) : NULL;
533 return join_path(p, path, suffix, fs);
536 static int check_hierarchy(const char *p) {
541 /* Check if this controller actually really exists */
542 cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(p));
543 strcpy(stpcpy(cc, "/sys/fs/cgroup/"), p);
544 if (access(cc, F_OK) < 0)
550 int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) {
556 if (!cg_controller_is_valid(controller, true))
559 /* Normalize the controller syntax */
560 p = normalize_controller(controller);
562 /* Check if this controller actually really exists */
563 r = check_hierarchy(p);
567 return join_path(p, path, suffix, fs);
570 static int trim_cb(const char *path, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
575 if (typeflag != FTW_DP)
578 if (ftwbuf->level < 1)
585 int cg_trim(const char *controller, const char *path, bool delete_root) {
586 _cleanup_free_ char *fs = NULL;
591 r = cg_get_path(controller, path, NULL, &fs);
596 if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0)
597 r = errno ? -errno : -EIO;
600 if (rmdir(fs) < 0 && errno != ENOENT)
607 int cg_delete(const char *controller, const char *path) {
608 _cleanup_free_ char *parent = NULL;
613 r = path_get_parent(path, &parent);
617 r = cg_migrate_recursive(controller, path, controller, parent, false, true);
618 return r == -ENOENT ? 0 : r;
621 int cg_attach(const char *controller, const char *path, pid_t pid) {
622 _cleanup_free_ char *fs = NULL;
623 char c[DECIMAL_STR_MAX(pid_t) + 2];
629 r = cg_get_path_and_check(controller, path, "cgroup.procs", &fs);
636 snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
638 return write_string_file(fs, c);
641 int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
648 r = cg_attach(controller, path, pid);
650 char prefix[strlen(path) + 1];
652 /* This didn't work? Then let's try all prefixes of
655 PATH_FOREACH_PREFIX(prefix, path) {
656 r = cg_attach(controller, prefix, pid);
665 int cg_set_group_access(
666 const char *controller,
672 _cleanup_free_ char *fs = NULL;
677 if (mode != (mode_t) -1)
680 r = cg_get_path(controller, path, NULL, &fs);
684 return chmod_and_chown(fs, mode, uid, gid);
687 int cg_set_task_access(
688 const char *controller,
694 _cleanup_free_ char *fs = NULL, *procs = NULL;
699 if (mode == (mode_t) -1 && uid == (uid_t) -1 && gid == (gid_t) -1)
702 if (mode != (mode_t) -1)
705 r = cg_get_path(controller, path, "cgroup.procs", &fs);
709 r = chmod_and_chown(fs, mode, uid, gid);
713 /* Compatibility, Always keep values for "tasks" in sync with
715 r = cg_get_path(controller, path, "tasks", &procs);
719 return chmod_and_chown(procs, mode, uid, gid);
722 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
723 _cleanup_fclose_ FILE *f = NULL;
732 if (!cg_controller_is_valid(controller, true))
735 controller = normalize_controller(controller);
737 controller = SYSTEMD_CGROUP_CONTROLLER;
740 fs = "/proc/self/cgroup";
742 fs = procfs_file_alloca(pid, "cgroup");
746 return errno == ENOENT ? -ESRCH : -errno;
748 cs = strlen(controller);
750 FOREACH_LINE(line, f, return -errno) {
758 l = strchr(line, ':');
769 FOREACH_WORD_SEPARATOR(w, k, l, ",", state) {
771 if (k == cs && memcmp(w, controller, cs) == 0) {
777 memcmp(w, "name=", 5) == 0 &&
778 memcmp(w+5, controller, cs) == 0) {
798 int cg_install_release_agent(const char *controller, const char *agent) {
799 _cleanup_free_ char *fs = NULL, *contents = NULL;
805 r = cg_get_path(controller, NULL, "release_agent", &fs);
809 r = read_one_line_file(fs, &contents);
813 sc = strstrip(contents);
815 r = write_string_file(fs, agent);
818 } else if (!streq(sc, agent))
823 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
829 r = read_one_line_file(fs, &contents);
833 sc = strstrip(contents);
834 if (streq(sc, "0")) {
835 r = write_string_file(fs, "1");
848 int cg_uninstall_release_agent(const char *controller) {
849 _cleanup_free_ char *fs = NULL;
852 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
856 r = write_string_file(fs, "0");
863 r = cg_get_path(controller, NULL, "release_agent", &fs);
867 r = write_string_file(fs, "");
874 int cg_is_empty(const char *controller, const char *path, bool ignore_self) {
875 _cleanup_fclose_ FILE *f = NULL;
876 pid_t pid = 0, self_pid;
882 r = cg_enumerate_processes(controller, path, &f);
884 return r == -ENOENT ? 1 : r;
888 while ((r = cg_read_pid(f, &pid)) > 0) {
890 if (ignore_self && pid == self_pid)
903 int cg_is_empty_by_spec(const char *spec, bool ignore_self) {
904 _cleanup_free_ char *controller = NULL, *path = NULL;
909 r = cg_split_spec(spec, &controller, &path);
913 return cg_is_empty(controller, path, ignore_self);
916 int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self) {
917 _cleanup_closedir_ DIR *d = NULL;
923 r = cg_is_empty(controller, path, ignore_self);
927 r = cg_enumerate_subgroups(controller, path, &d);
929 return r == -ENOENT ? 1 : r;
931 while ((r = cg_read_subgroup(d, &fn)) > 0) {
932 _cleanup_free_ char *p = NULL;
934 p = strjoin(path, "/", fn, NULL);
939 r = cg_is_empty_recursive(controller, p, ignore_self);
950 int cg_split_spec(const char *spec, char **controller, char **path) {
952 char *t = NULL, *u = NULL;
953 _cleanup_free_ char *v = NULL;
958 if (!path_is_safe(spec))
966 path_kill_slashes(t);
976 e = strchr(spec, ':');
978 if (!cg_controller_is_valid(spec, true))
982 t = strdup(normalize_controller(spec));
995 v = strndup(spec, e-spec);
998 t = strdup(normalize_controller(v));
1001 if (!cg_controller_is_valid(t, true)) {
1011 if (!path_is_safe(u) ||
1012 !path_is_absolute(u)) {
1018 path_kill_slashes(u);
1033 int cg_join_spec(const char *controller, const char *path, char **spec) {
1039 controller = "systemd";
1041 if (!cg_controller_is_valid(controller, true))
1044 controller = normalize_controller(controller);
1047 if (!path_is_absolute(path))
1050 s = strjoin(controller, ":", path, NULL);
1054 path_kill_slashes(s + strlen(controller) + 1);
1060 int cg_mangle_path(const char *path, char **result) {
1061 _cleanup_free_ char *c = NULL, *p = NULL;
1068 /* First check if it already is a filesystem path */
1069 if (path_startswith(path, "/sys/fs/cgroup")) {
1075 path_kill_slashes(t);
1080 /* Otherwise treat it as cg spec */
1081 r = cg_split_spec(path, &c, &p);
1085 return cg_get_path(c ? c : SYSTEMD_CGROUP_CONTROLLER, p ? p : "/", NULL, result);
1088 int cg_get_root_path(char **path) {
1094 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 1, &p);
1098 e = endswith(p, "/" SPECIAL_SYSTEM_SLICE);
1106 char **cg_shorten_controllers(char **controllers) {
1112 for (f = controllers, t = controllers; *f; f++) {
1116 p = normalize_controller(*f);
1118 if (streq(p, "systemd")) {
1123 if (!cg_controller_is_valid(p, true)) {
1124 log_warning("Controller %s is not valid, removing from controllers list.", p);
1129 r = check_hierarchy(p);
1131 log_debug("Controller %s is not available, removing from controllers list.", p);
1140 return strv_uniq(controllers);
1143 int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) {
1144 _cleanup_free_ char *cg_root = NULL;
1145 char *cg_process, *p;
1148 r = cg_get_root_path(&cg_root);
1152 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cg_process);
1156 p = path_startswith(cg_process, cg_root);
1175 cg_process[p-cg_process] = 0;
1183 int cg_path_decode_unit(const char *cgroup, char **unit){
1189 e = strchrnul(cgroup, '/');
1190 c = strndupa(cgroup, e - cgroup);
1193 if (!unit_name_is_valid(c, false))
1204 static const char *skip_slices(const char *p) {
1205 /* Skips over all slice assignments */
1210 p += strspn(p, "/");
1212 n = strcspn(p, "/");
1213 if (n <= 6 || memcmp(p + n - 6, ".slice", 6) != 0)
1220 int cg_path_get_unit(const char *path, char **unit) {
1226 e = skip_slices(path);
1228 return cg_path_decode_unit(e, unit);
1231 int cg_pid_get_unit(pid_t pid, char **unit) {
1232 _cleanup_free_ char *cgroup = NULL;
1237 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1241 return cg_path_get_unit(cgroup, unit);
1244 static const char *skip_session(const char *p) {
1249 p += strspn(p, "/");
1251 n = strcspn(p, "/");
1252 if (n <= 12 || memcmp(p, "session-", 8) != 0 || memcmp(p + n - 6, ".scope", 6) != 0)
1256 p += strspn(p, "/");
1261 int cg_path_get_user_unit(const char *path, char **unit) {
1267 /* We always have to parse the path from the beginning as unit
1268 * cgroups might have arbitrary child cgroups and we shouldn't get
1269 * confused by those */
1271 /* Skip slices, if there are any */
1272 e = skip_slices(path);
1274 /* Skip the session scope, require that there is one */
1275 e = skip_session(e);
1279 /* And skip more slices */
1282 return cg_path_decode_unit(e, unit);
1285 int cg_pid_get_user_unit(pid_t pid, char **unit) {
1286 _cleanup_free_ char *cgroup = NULL;
1291 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1295 return cg_path_get_user_unit(cgroup, unit);
1298 int cg_path_get_machine_name(const char *path, char **machine) {
1299 const char *e, *n, *x;
1306 /* Skip slices, if there are any */
1307 e = skip_slices(path);
1309 n = strchrnul(e, '/');
1313 s = strndupa(e, n - e);
1316 x = startswith(s, "machine-");
1319 if (!endswith(x, ".scope"))
1326 r = strndup(x, l - 6);
1334 int cg_pid_get_machine_name(pid_t pid, char **machine) {
1335 _cleanup_free_ char *cgroup = NULL;
1340 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1344 return cg_path_get_machine_name(cgroup, machine);
1347 int cg_path_get_session(const char *path, char **session) {
1348 const char *e, *n, *x;
1355 /* Skip slices, if there are any */
1356 e = skip_slices(path);
1358 n = strchrnul(e, '/');
1362 s = strndupa(e, n - e);
1365 x = startswith(s, "session-");
1368 if (!endswith(x, ".scope"))
1375 r = strndup(x, l - 6);
1383 int cg_pid_get_session(pid_t pid, char **session) {
1384 _cleanup_free_ char *cgroup = NULL;
1389 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1393 return cg_path_get_session(cgroup, session);
1396 int cg_path_get_owner_uid(const char *path, uid_t *uid) {
1397 _cleanup_free_ char *slice = NULL;
1405 r = cg_path_get_slice(path, &slice);
1409 e = startswith(slice, "user-");
1412 if (!endswith(slice, ".slice"))
1415 s = strndupa(e, strlen(e) - 6);
1419 return parse_uid(s, uid);
1422 int cg_pid_get_owner_uid(pid_t pid, uid_t *uid) {
1423 _cleanup_free_ char *cgroup = NULL;
1428 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1432 return cg_path_get_owner_uid(cgroup, uid);
1435 int cg_path_get_slice(const char *p, char **slice) {
1436 const char *e = NULL;
1445 p += strspn(p, "/");
1447 n = strcspn(p, "/");
1448 if (n <= 6 || memcmp(p + n - 6, ".slice", 6) != 0) {
1469 int cg_pid_get_slice(pid_t pid, char **slice) {
1470 _cleanup_free_ char *cgroup = NULL;
1475 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1479 return cg_path_get_slice(cgroup, slice);
1482 int cg_controller_from_attr(const char *attr, char **controller) {
1489 if (!filename_is_safe(attr))
1492 dot = strchr(attr, '.');
1498 c = strndup(attr, dot - attr);
1502 if (!cg_controller_is_valid(c, false)) {
1511 char *cg_escape(const char *p) {
1512 bool need_prefix = false;
1514 /* This implements very minimal escaping for names to be used
1515 * as file names in the cgroup tree: any name which might
1516 * conflict with a kernel name or is prefixed with '_' is
1517 * prefixed with a '_'. That way, when reading cgroup names it
1518 * is sufficient to remove a single prefixing underscore if
1521 /* The return value of this function (unlike cg_unescape())
1527 streq(p, "notify_on_release") ||
1528 streq(p, "release_agent") ||
1534 dot = strrchr(p, '.');
1537 if (dot - p == 6 && memcmp(p, "cgroup", 6) == 0)
1542 n = strndupa(p, dot - p);
1544 if (check_hierarchy(n) >= 0)
1551 return strappend("_", p);
1556 char *cg_unescape(const char *p) {
1559 /* The return value of this function (unlike cg_escape())
1560 * doesn't need free()! */
1568 #define CONTROLLER_VALID \
1572 bool cg_controller_is_valid(const char *p, bool allow_named) {
1579 s = startswith(p, "name=");
1584 if (*p == 0 || *p == '_')
1587 for (t = p; *t; t++)
1588 if (!strchr(CONTROLLER_VALID, *t))
1591 if (t - p > FILENAME_MAX)
1597 int cg_slice_to_path(const char *unit, char **ret) {
1598 _cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
1604 if (!unit_name_is_valid(unit, false))
1607 if (!endswith(unit, ".slice"))
1610 p = unit_name_to_prefix(unit);
1614 dash = strchr(p, '-');
1616 _cleanup_free_ char *escaped = NULL;
1617 char n[dash - p + sizeof(".slice")];
1619 strcpy(stpncpy(n, p, dash - p), ".slice");
1621 if (!unit_name_is_valid(n, false))
1624 escaped = cg_escape(n);
1628 if (!strextend(&s, escaped, "/", NULL))
1631 dash = strchr(dash+1, '-');
1634 e = cg_escape(unit);
1638 if (!strextend(&s, e, NULL))
1647 int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
1648 _cleanup_free_ char *p = NULL;
1651 r = cg_get_path(controller, path, attribute, &p);
1655 return write_string_file(p, value);
1658 static const char mask_names[] =
1665 int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path) {
1666 CGroupControllerMask bit = 1;
1670 /* This one will create a cgroup in our private tree, but also
1671 * duplicate it in the trees specified in mask, and remove it
1674 /* First create the cgroup in our own hierarchy. */
1675 r = cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
1679 /* Then, do the same in the other hierarchies */
1680 NULSTR_FOREACH(n, mask_names) {
1683 else if (supported & bit)
1684 cg_trim(n, path, true);
1692 int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid) {
1693 CGroupControllerMask bit = 1;
1697 r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
1701 NULSTR_FOREACH(n, mask_names) {
1702 if (supported & bit)
1703 cg_attach_fallback(n, path, pid);
1711 int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids) {
1716 SET_FOREACH(pidp, pids, i) {
1717 pid_t pid = PTR_TO_LONG(pidp);
1720 q = cg_attach_everywhere(supported, path, pid);
1728 int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to) {
1729 CGroupControllerMask bit = 1;
1733 if (!path_equal(from, to)) {
1734 r = cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, from, SYSTEMD_CGROUP_CONTROLLER, to, false, true);
1739 NULSTR_FOREACH(n, mask_names) {
1740 if (supported & bit)
1741 cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, n, to, false, false);
1749 int cg_trim_everywhere(CGroupControllerMask supported, const char *path, bool delete_root) {
1750 CGroupControllerMask bit = 1;
1754 r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
1758 NULSTR_FOREACH(n, mask_names) {
1759 if (supported & bit)
1760 cg_trim(n, path, delete_root);
1768 CGroupControllerMask cg_mask_supported(void) {
1769 CGroupControllerMask bit = 1, mask = 0;
1772 NULSTR_FOREACH(n, mask_names) {
1773 if (check_hierarchy(n) >= 0)