2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 //#include <sys/statfs.h>
30 #include <sys/types.h>
31 #include <sys/xattr.h>
34 #include "alloc-util.h"
35 #include "cgroup-util.h"
37 #include "dirent-util.h"
38 #include "extract-word.h"
41 #include "format-util.h"
44 #include "login-util.h"
46 //#include "missing.h"
48 #include "parse-util.h"
49 #include "path-util.h"
50 #include "proc-cmdline.h"
51 #include "process-util.h"
53 //#include "special.h"
54 #include "stat-util.h"
55 #include "stdio-util.h"
56 #include "string-table.h"
57 #include "string-util.h"
59 #include "unit-name.h"
60 #include "user-util.h"
62 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
63 _cleanup_free_ char *fs = NULL;
69 r = cg_get_path(controller, path, "cgroup.procs", &fs);
81 int cg_read_pid(FILE *f, pid_t *_pid) {
84 /* Note that the cgroup.procs might contain duplicates! See
85 * cgroups.txt for details. */
91 if (fscanf(f, "%lu", &ul) != 1) {
96 return errno > 0 ? -errno : -EIO;
106 int cg_read_event(const char *controller, const char *path, const char *event,
109 _cleanup_free_ char *events = NULL, *content = NULL;
113 r = cg_get_path(controller, path, "cgroup.events", &events);
117 r = read_full_file(events, &content, NULL);
122 while ((line = strsep(&p, "\n"))) {
125 key = strsep(&line, " ");
129 if (strcmp(key, event))
139 #if 0 /// UNNEEDED by elogind
140 bool cg_ns_supported(void) {
141 static thread_local int enabled = -1;
146 if (access("/proc/self/ns/cgroup", F_OK) == 0)
155 int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
156 _cleanup_free_ char *fs = NULL;
162 /* This is not recursive! */
164 r = cg_get_path(controller, path, NULL, &fs);
176 int cg_read_subgroup(DIR *d, char **fn) {
182 FOREACH_DIRENT_ALL(de, d, return -errno) {
185 if (de->d_type != DT_DIR)
188 if (dot_or_dot_dot(de->d_name))
191 b = strdup(de->d_name);
202 int cg_rmdir(const char *controller, const char *path) {
203 _cleanup_free_ char *p = NULL;
206 r = cg_get_path(controller, path, NULL, &p);
211 if (r < 0 && errno != ENOENT)
214 r = cg_hybrid_unified();
220 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
221 r = cg_rmdir(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path);
223 log_warning_errno(r, "Failed to remove compat systemd cgroup %s: %m", path);
230 const char *controller,
235 cg_kill_log_func_t log_kill,
238 _cleanup_set_free_ Set *allocated_set = NULL;
245 /* Don't send SIGCONT twice. Also, SIGKILL always works even when process is suspended, hence don't send
246 * SIGCONT on SIGKILL. */
247 if (IN_SET(sig, SIGCONT, SIGKILL))
248 flags &= ~CGROUP_SIGCONT;
250 /* This goes through the tasks list and kills them all. This
251 * is repeated until no further processes are added to the
252 * tasks list, to properly handle forking processes */
255 s = allocated_set = set_new(NULL);
263 _cleanup_fclose_ FILE *f = NULL;
267 r = cg_enumerate_processes(controller, path, &f);
269 if (ret >= 0 && r != -ENOENT)
275 while ((r = cg_read_pid(f, &pid)) > 0) {
277 if ((flags & CGROUP_IGNORE_SELF) && pid == my_pid)
280 if (set_get(s, PID_TO_PTR(pid)) == PID_TO_PTR(pid))
284 log_kill(pid, sig, userdata);
286 /* If we haven't killed this process yet, kill
288 if (kill(pid, sig) < 0) {
289 if (ret >= 0 && errno != ESRCH)
292 if (flags & CGROUP_SIGCONT)
293 (void) kill(pid, SIGCONT);
301 r = set_put(s, PID_TO_PTR(pid));
317 /* To avoid racing against processes which fork
318 * quicker than we can kill them we repeat this until
319 * no new pids need to be killed. */
326 int cg_kill_recursive(
327 const char *controller,
332 cg_kill_log_func_t log_kill,
335 _cleanup_set_free_ Set *allocated_set = NULL;
336 _cleanup_closedir_ DIR *d = NULL;
344 s = allocated_set = set_new(NULL);
349 ret = cg_kill(controller, path, sig, flags, s, log_kill, userdata);
351 r = cg_enumerate_subgroups(controller, path, &d);
353 if (ret >= 0 && r != -ENOENT)
359 while ((r = cg_read_subgroup(d, &fn)) > 0) {
360 _cleanup_free_ char *p = NULL;
362 p = strjoin(path, "/", fn);
367 r = cg_kill_recursive(controller, p, sig, flags, s, log_kill, userdata);
368 if (r != 0 && ret >= 0)
371 if (ret >= 0 && r < 0)
374 if (flags & CGROUP_REMOVE) {
375 r = cg_rmdir(controller, path);
376 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
391 _cleanup_set_free_ Set *s = NULL;
406 log_debug_elogind("Migrating \"%s\"/\"%s\" to \"%s\"/\"%s\" (%s)",
407 cfrom, pfrom, cto, pto,
408 (flags & CGROUP_IGNORE_SELF)
409 ? "ignoring self" : "watching self");
411 _cleanup_fclose_ FILE *f = NULL;
415 r = cg_enumerate_processes(cfrom, pfrom, &f);
417 if (ret >= 0 && r != -ENOENT)
423 while ((r = cg_read_pid(f, &pid)) > 0) {
425 /* This might do weird stuff if we aren't a
426 * single-threaded program. However, we
427 * luckily know we are not */
428 if ((flags & CGROUP_IGNORE_SELF) && pid == my_pid)
431 if (set_get(s, PID_TO_PTR(pid)) == PID_TO_PTR(pid))
434 /* Ignore kernel threads. Since they can only
435 * exist in the root cgroup, we only check for
438 (isempty(pfrom) || path_equal(pfrom, "/")) &&
439 is_kernel_thread(pid) > 0)
442 r = cg_attach(cto, pto, pid);
444 if (ret >= 0 && r != -ESRCH)
451 r = set_put(s, PID_TO_PTR(pid));
471 int cg_migrate_recursive(
478 _cleanup_closedir_ DIR *d = NULL;
487 ret = cg_migrate(cfrom, pfrom, cto, pto, flags);
489 r = cg_enumerate_subgroups(cfrom, pfrom, &d);
491 if (ret >= 0 && r != -ENOENT)
497 while ((r = cg_read_subgroup(d, &fn)) > 0) {
498 _cleanup_free_ char *p = NULL;
500 p = strjoin(pfrom, "/", fn);
505 r = cg_migrate_recursive(cfrom, p, cto, pto, flags);
506 if (r != 0 && ret >= 0)
510 if (r < 0 && ret >= 0)
513 if (flags & CGROUP_REMOVE) {
514 r = cg_rmdir(cfrom, pfrom);
515 if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
522 int cg_migrate_recursive_fallback(
536 r = cg_migrate_recursive(cfrom, pfrom, cto, pto, flags);
538 char prefix[strlen(pto) + 1];
540 /* This didn't work? Then let's try all prefixes of the destination */
542 PATH_FOREACH_PREFIX(prefix, pto) {
545 q = cg_migrate_recursive(cfrom, pfrom, cto, prefix, flags);
554 static const char *controller_to_dirname(const char *controller) {
559 /* Converts a controller name to the directory name below
560 * /sys/fs/cgroup/ we want to mount it to. Effectively, this
561 * just cuts off the name= prefixed used for named
562 * hierarchies, if it is specified. */
564 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
565 if (cg_hybrid_unified() > 0)
566 controller = SYSTEMD_CGROUP_CONTROLLER_HYBRID;
568 controller = SYSTEMD_CGROUP_CONTROLLER_LEGACY;
571 e = startswith(controller, "name=");
578 static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **fs) {
585 dn = controller_to_dirname(controller);
587 if (isempty(path) && isempty(suffix))
588 t = strappend("/sys/fs/cgroup/", dn);
589 else if (isempty(path))
590 t = strjoin("/sys/fs/cgroup/", dn, "/", suffix);
591 else if (isempty(suffix))
592 t = strjoin("/sys/fs/cgroup/", dn, "/", path);
594 t = strjoin("/sys/fs/cgroup/", dn, "/", path, "/", suffix);
602 static int join_path_unified(const char *path, const char *suffix, char **fs) {
607 if (isempty(path) && isempty(suffix))
608 t = strdup("/sys/fs/cgroup");
609 else if (isempty(path))
610 t = strappend("/sys/fs/cgroup/", suffix);
611 else if (isempty(suffix))
612 t = strappend("/sys/fs/cgroup/", path);
614 t = strjoin("/sys/fs/cgroup/", path, "/", suffix);
622 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
630 /* If no controller is specified, we return the path
631 * *below* the controllers, without any prefix. */
633 if (!path && !suffix)
641 t = strjoin(path, "/", suffix);
645 *fs = path_kill_slashes(t);
649 if (!cg_controller_is_valid(controller))
652 r = cg_all_unified();
656 r = join_path_unified(path, suffix, fs);
658 r = join_path_legacy(controller, path, suffix, fs);
662 path_kill_slashes(*fs);
666 static int controller_is_accessible(const char *controller) {
671 /* Checks whether a specific controller is accessible,
672 * i.e. its hierarchy mounted. In the unified hierarchy all
673 * controllers are considered accessible, except for the named
676 if (!cg_controller_is_valid(controller))
679 r = cg_all_unified();
683 /* We don't support named hierarchies if we are using
684 * the unified hierarchy. */
686 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
689 if (startswith(controller, "name="))
695 dn = controller_to_dirname(controller);
696 cc = strjoina("/sys/fs/cgroup/", dn);
698 if (laccess(cc, F_OK) < 0)
705 int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) {
711 /* Check if the specified controller is actually accessible */
712 r = controller_is_accessible(controller);
716 return cg_get_path(controller, path, suffix, fs);
719 static int trim_cb(const char *path, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
724 if (typeflag != FTW_DP)
727 if (ftwbuf->level < 1)
734 int cg_trim(const char *controller, const char *path, bool delete_root) {
735 _cleanup_free_ char *fs = NULL;
740 r = cg_get_path(controller, path, NULL, &fs);
745 if (nftw(fs, trim_cb, 64, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) != 0) {
755 if (rmdir(fs) < 0 && errno != ENOENT)
759 q = cg_hybrid_unified();
762 if (q > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
763 q = cg_trim(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, delete_root);
765 log_warning_errno(q, "Failed to trim compat systemd cgroup %s: %m", path);
771 int cg_create(const char *controller, const char *path) {
772 _cleanup_free_ char *fs = NULL;
775 r = cg_get_path_and_check(controller, path, NULL, &fs);
779 r = mkdir_parents(fs, 0755);
783 if (mkdir(fs, 0755) < 0) {
791 r = cg_hybrid_unified();
795 if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
796 r = cg_create(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path);
798 log_warning_errno(r, "Failed to create compat systemd cgroup %s: %m", path);
804 int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
809 r = cg_create(controller, path);
813 q = cg_attach(controller, path, pid);
817 /* This does not remove the cgroup on failure */
821 int cg_attach(const char *controller, const char *path, pid_t pid) {
822 _cleanup_free_ char *fs = NULL;
823 char c[DECIMAL_STR_MAX(pid_t) + 2];
829 r = cg_get_path_and_check(controller, path, "cgroup.procs", &fs);
836 xsprintf(c, PID_FMT "\n", pid);
838 r = write_string_file(fs, c, 0);
842 r = cg_hybrid_unified();
846 if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
847 r = cg_attach(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, pid);
849 log_warning_errno(r, "Failed to attach "PID_FMT" to compat systemd cgroup %s: %m", pid, path);
855 int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
862 r = cg_attach(controller, path, pid);
864 char prefix[strlen(path) + 1];
866 /* This didn't work? Then let's try all prefixes of
869 PATH_FOREACH_PREFIX(prefix, path) {
872 q = cg_attach(controller, prefix, pid);
881 #if 0 /// UNNEEDED by elogind
882 int cg_set_group_access(
883 const char *controller,
889 _cleanup_free_ char *fs = NULL;
892 if (mode == MODE_INVALID && uid == UID_INVALID && gid == GID_INVALID)
895 if (mode != MODE_INVALID)
898 r = cg_get_path(controller, path, NULL, &fs);
902 r = chmod_and_chown(fs, mode, uid, gid);
906 r = cg_hybrid_unified();
909 if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
910 r = cg_set_group_access(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, mode, uid, gid);
912 log_warning_errno(r, "Failed to set group access on compat systemd cgroup %s: %m", path);
918 int cg_set_task_access(
919 const char *controller,
925 _cleanup_free_ char *fs = NULL, *procs = NULL;
930 if (mode == MODE_INVALID && uid == UID_INVALID && gid == GID_INVALID)
933 if (mode != MODE_INVALID)
936 r = cg_get_path(controller, path, "cgroup.procs", &fs);
940 r = chmod_and_chown(fs, mode, uid, gid);
944 r = cg_unified_controller(controller);
948 /* Compatibility, Always keep values for "tasks" in sync with
950 if (cg_get_path(controller, path, "tasks", &procs) >= 0)
951 (void) chmod_and_chown(procs, mode, uid, gid);
954 r = cg_hybrid_unified();
957 if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) {
958 r = cg_set_task_access(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, mode, uid, gid);
960 log_warning_errno(r, "Failed to set task access on compat systemd cgroup %s: %m", path);
966 int cg_set_xattr(const char *controller, const char *path, const char *name, const void *value, size_t size, int flags) {
967 _cleanup_free_ char *fs = NULL;
972 assert(value || size <= 0);
974 r = cg_get_path(controller, path, NULL, &fs);
978 if (setxattr(fs, name, value, size, flags) < 0)
984 int cg_get_xattr(const char *controller, const char *path, const char *name, void *value, size_t size) {
985 _cleanup_free_ char *fs = NULL;
992 r = cg_get_path(controller, path, NULL, &fs);
996 n = getxattr(fs, name, value, size);
1004 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
1005 _cleanup_fclose_ FILE *f = NULL;
1006 char line[LINE_MAX];
1007 const char *fs, *controller_str = NULL;
1015 if (!cg_controller_is_valid(controller))
1018 controller = SYSTEMD_CGROUP_CONTROLLER;
1020 unified = cg_unified_controller(controller);
1024 if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
1025 controller_str = SYSTEMD_CGROUP_CONTROLLER_LEGACY;
1027 controller_str = controller;
1029 cs = strlen(controller_str);
1032 fs = procfs_file_alloca(pid, "cgroup");
1033 log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
1034 pid, fs, controller);
1035 f = fopen(fs, "re");
1037 return errno == ENOENT ? -ESRCH : -errno;
1039 FOREACH_LINE(line, f, return -errno) {
1045 e = startswith(line, "0:");
1055 const char *word, *state;
1058 l = strchr(line, ':');
1068 FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
1069 if (k == cs && memcmp(word, controller_str, cs) == 0) {
1079 log_debug_elogind("Found %s:%s", line, e+1);
1091 int cg_install_release_agent(const char *controller, const char *agent) {
1092 _cleanup_free_ char *fs = NULL, *contents = NULL;
1098 r = cg_unified_controller(controller);
1101 if (r > 0) /* doesn't apply to unified hierarchy */
1104 r = cg_get_path(controller, NULL, "release_agent", &fs);
1108 r = read_one_line_file(fs, &contents);
1112 sc = strstrip(contents);
1114 r = write_string_file(fs, agent, 0);
1117 } else if (!path_equal(sc, agent))
1121 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
1125 contents = mfree(contents);
1126 r = read_one_line_file(fs, &contents);
1130 sc = strstrip(contents);
1131 if (streq(sc, "0")) {
1132 r = write_string_file(fs, "1", 0);
1139 if (!streq(sc, "1"))
1145 int cg_uninstall_release_agent(const char *controller) {
1146 _cleanup_free_ char *fs = NULL;
1149 r = cg_unified_controller(controller);
1152 if (r > 0) /* Doesn't apply to unified hierarchy */
1155 r = cg_get_path(controller, NULL, "notify_on_release", &fs);
1159 r = write_string_file(fs, "0", 0);
1165 r = cg_get_path(controller, NULL, "release_agent", &fs);
1169 r = write_string_file(fs, "", 0);
1176 int cg_is_empty(const char *controller, const char *path) {
1177 _cleanup_fclose_ FILE *f = NULL;
1183 r = cg_enumerate_processes(controller, path, &f);
1189 r = cg_read_pid(f, &pid);
1196 int cg_is_empty_recursive(const char *controller, const char *path) {
1201 /* The root cgroup is always populated */
1202 if (controller && (isempty(path) || path_equal(path, "/")))
1205 r = cg_unified_controller(controller);
1209 _cleanup_free_ char *t = NULL;
1211 /* On the unified hierarchy we can check empty state
1212 * via the "populated" attribute of "cgroup.events". */
1214 r = cg_read_event(controller, path, "populated", &t);
1218 return streq(t, "0");
1220 _cleanup_closedir_ DIR *d = NULL;
1223 r = cg_is_empty(controller, path);
1227 r = cg_enumerate_subgroups(controller, path, &d);
1233 while ((r = cg_read_subgroup(d, &fn)) > 0) {
1234 _cleanup_free_ char *p = NULL;
1236 p = strjoin(path, "/", fn);
1241 r = cg_is_empty_recursive(controller, p);
1252 int cg_split_spec(const char *spec, char **controller, char **path) {
1253 char *t = NULL, *u = NULL;
1259 if (!path_is_safe(spec))
1267 *path = path_kill_slashes(t);
1276 e = strchr(spec, ':');
1278 if (!cg_controller_is_valid(spec))
1295 t = strndup(spec, e-spec);
1298 if (!cg_controller_is_valid(t)) {
1312 if (!path_is_safe(u) ||
1313 !path_is_absolute(u)) {
1319 path_kill_slashes(u);
1335 int cg_mangle_path(const char *path, char **result) {
1336 _cleanup_free_ char *c = NULL, *p = NULL;
1343 /* First, check if it already is a filesystem path */
1344 if (path_startswith(path, "/sys/fs/cgroup")) {
1350 *result = path_kill_slashes(t);
1354 /* Otherwise, treat it as cg spec */
1355 r = cg_split_spec(path, &c, &p);
1359 return cg_get_path(c ?: SYSTEMD_CGROUP_CONTROLLER, p ?: "/", NULL, result);
1362 int cg_get_root_path(char **path) {
1363 #if 0 /// elogind does not support systemd scopes and slices
1369 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 1, &p);
1373 e = endswith(p, "/" SPECIAL_INIT_SCOPE);
1375 e = endswith(p, "/" SPECIAL_SYSTEM_SLICE); /* legacy */
1377 e = endswith(p, "/system"); /* even more legacy */
1385 return cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 1, path);
1389 int cg_shift_path(const char *cgroup, const char *root, const char **shifted) {
1390 _cleanup_free_ char *rt = NULL;
1398 /* If the root was specified let's use that, otherwise
1399 * let's determine it from PID 1 */
1401 r = cg_get_root_path(&rt);
1406 log_debug_elogind("Determined root path: \"%s\"", root);
1409 p = path_startswith(cgroup, root);
1410 #if 0 /// With other controllers, elogind might end up in /elogind, and *p is 0
1411 if (p && p > cgroup)
1413 if (p && p[0] && (p > cgroup))
1422 int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
1423 _cleanup_free_ char *raw = NULL;
1430 r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &raw);
1434 log_debug_elogind("Shifting path: \"%s\" (PID %u, root: \"%s\")",
1435 raw, pid, root ? root : "NULL");
1436 r = cg_shift_path(raw, root, &c);
1452 log_debug_elogind("Resulting cgroup:\"%s\"", *cgroup);
1457 #if 0 /// UNNEEDED by elogind
1458 int cg_path_decode_unit(const char *cgroup, char **unit) {
1465 n = strcspn(cgroup, "/");
1469 c = strndupa(cgroup, n);
1472 if (!unit_name_is_valid(c, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
1483 static bool valid_slice_name(const char *p, size_t n) {
1488 if (n < strlen("x.slice"))
1491 if (memcmp(p + n - 6, ".slice", 6) == 0) {
1497 c = cg_unescape(buf);
1499 return unit_name_is_valid(c, UNIT_NAME_PLAIN);
1505 static const char *skip_slices(const char *p) {
1508 /* Skips over all slice assignments */
1513 p += strspn(p, "/");
1515 n = strcspn(p, "/");
1516 if (!valid_slice_name(p, n))
1523 int cg_path_get_unit(const char *path, char **ret) {
1531 e = skip_slices(path);
1533 r = cg_path_decode_unit(e, &unit);
1537 /* We skipped over the slices, don't accept any now */
1538 if (endswith(unit, ".slice")) {
1547 int cg_pid_get_unit(pid_t pid, char **unit) {
1548 _cleanup_free_ char *cgroup = NULL;
1553 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1557 return cg_path_get_unit(cgroup, unit);
1561 * Skip session-*.scope, but require it to be there.
1563 static const char *skip_session(const char *p) {
1569 p += strspn(p, "/");
1571 n = strcspn(p, "/");
1572 if (n < strlen("session-x.scope"))
1575 if (memcmp(p, "session-", 8) == 0 && memcmp(p + n - 6, ".scope", 6) == 0) {
1576 char buf[n - 8 - 6 + 1];
1578 memcpy(buf, p + 8, n - 8 - 6);
1581 /* Note that session scopes never need unescaping,
1582 * since they cannot conflict with the kernel's own
1583 * names, hence we don't need to call cg_unescape()
1586 if (!session_id_valid(buf))
1590 p += strspn(p, "/");
1598 * Skip user@*.service, but require it to be there.
1600 static const char *skip_user_manager(const char *p) {
1606 p += strspn(p, "/");
1608 n = strcspn(p, "/");
1609 if (n < strlen("user@x.service"))
1612 if (memcmp(p, "user@", 5) == 0 && memcmp(p + n - 8, ".service", 8) == 0) {
1613 char buf[n - 5 - 8 + 1];
1615 memcpy(buf, p + 5, n - 5 - 8);
1618 /* Note that user manager services never need unescaping,
1619 * since they cannot conflict with the kernel's own
1620 * names, hence we don't need to call cg_unescape()
1623 if (parse_uid(buf, NULL) < 0)
1627 p += strspn(p, "/");
1635 static const char *skip_user_prefix(const char *path) {
1640 /* Skip slices, if there are any */
1641 e = skip_slices(path);
1643 /* Skip the user manager, if it's in the path now... */
1644 t = skip_user_manager(e);
1648 /* Alternatively skip the user session if it is in the path... */
1649 return skip_session(e);
1652 int cg_path_get_user_unit(const char *path, char **ret) {
1658 t = skip_user_prefix(path);
1662 /* And from here on it looks pretty much the same as for a
1663 * system unit, hence let's use the same parser from here
1665 return cg_path_get_unit(t, ret);
1668 int cg_pid_get_user_unit(pid_t pid, char **unit) {
1669 _cleanup_free_ char *cgroup = NULL;
1674 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1678 return cg_path_get_user_unit(cgroup, unit);
1681 int cg_path_get_machine_name(const char *path, char **machine) {
1682 _cleanup_free_ char *u = NULL;
1686 r = cg_path_get_unit(path, &u);
1690 sl = strjoina("/run/systemd/machines/unit:", u);
1691 return readlink_malloc(sl, machine);
1694 int cg_pid_get_machine_name(pid_t pid, char **machine) {
1695 _cleanup_free_ char *cgroup = NULL;
1700 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1704 return cg_path_get_machine_name(cgroup, machine);
1708 int cg_path_get_session(const char *path, char **session) {
1709 #if 0 /// UNNEEDED by elogind
1710 _cleanup_free_ char *unit = NULL;
1716 r = cg_path_get_unit(path, &unit);
1720 start = startswith(unit, "session-");
1723 end = endswith(start, ".scope");
1728 if (!session_id_valid(start))
1731 /* Elogind uses a flat hierarchy, just "/SESSION". The only
1732 wrinkle is that SESSION might be escaped. */
1733 const char *e, *n, *start;
1736 log_debug_elogind("path is \"%s\"", path);
1737 assert(path[0] == '/');
1740 n = strchrnul(e, '/');
1744 start = strndupa(e, n - e);
1745 start = cg_unescape(start);
1754 log_debug_elogind("found session: \"%s\"", start);
1765 int cg_pid_get_session(pid_t pid, char **session) {
1766 _cleanup_free_ char *cgroup = NULL;
1769 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1773 return cg_path_get_session(cgroup, session);
1776 #if 0 /// UNNEEDED by elogind
1777 int cg_path_get_owner_uid(const char *path, uid_t *uid) {
1778 _cleanup_free_ char *slice = NULL;
1784 r = cg_path_get_slice(path, &slice);
1788 start = startswith(slice, "user-");
1791 end = endswith(start, ".slice");
1796 if (parse_uid(start, uid) < 0)
1802 int cg_pid_get_owner_uid(pid_t pid, uid_t *uid) {
1803 _cleanup_free_ char *cgroup = NULL;
1806 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1810 return cg_path_get_owner_uid(cgroup, uid);
1813 int cg_path_get_slice(const char *p, char **slice) {
1814 const char *e = NULL;
1819 /* Finds the right-most slice unit from the beginning, but
1820 * stops before we come to the first non-slice unit. */
1825 p += strspn(p, "/");
1827 n = strcspn(p, "/");
1828 if (!valid_slice_name(p, n)) {
1833 s = strdup(SPECIAL_ROOT_SLICE);
1841 return cg_path_decode_unit(e, slice);
1849 int cg_pid_get_slice(pid_t pid, char **slice) {
1850 _cleanup_free_ char *cgroup = NULL;
1855 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1859 return cg_path_get_slice(cgroup, slice);
1862 int cg_path_get_user_slice(const char *p, char **slice) {
1867 t = skip_user_prefix(p);
1871 /* And now it looks pretty much the same as for a system
1872 * slice, so let's just use the same parser from here on. */
1873 return cg_path_get_slice(t, slice);
1876 int cg_pid_get_user_slice(pid_t pid, char **slice) {
1877 _cleanup_free_ char *cgroup = NULL;
1882 r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
1886 return cg_path_get_user_slice(cgroup, slice);
1890 char *cg_escape(const char *p) {
1891 bool need_prefix = false;
1893 /* This implements very minimal escaping for names to be used
1894 * as file names in the cgroup tree: any name which might
1895 * conflict with a kernel name or is prefixed with '_' is
1896 * prefixed with a '_'. That way, when reading cgroup names it
1897 * is sufficient to remove a single prefixing underscore if
1900 /* The return value of this function (unlike cg_unescape())
1906 streq(p, "notify_on_release") ||
1907 streq(p, "release_agent") ||
1908 streq(p, "tasks") ||
1909 startswith(p, "cgroup."))
1914 dot = strrchr(p, '.');
1919 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
1922 n = cgroup_controller_to_string(c);
1927 if (memcmp(p, n, l) != 0)
1937 return strappend("_", p);
1942 char *cg_unescape(const char *p) {
1945 /* The return value of this function (unlike cg_escape())
1946 * doesn't need free()! */
1954 #define CONTROLLER_VALID \
1958 bool cg_controller_is_valid(const char *p) {
1964 if (streq(p, SYSTEMD_CGROUP_CONTROLLER))
1967 s = startswith(p, "name=");
1971 if (*p == 0 || *p == '_')
1974 for (t = p; *t; t++)
1975 if (!strchr(CONTROLLER_VALID, *t))
1978 if (t - p > FILENAME_MAX)
1984 #if 0 /// UNNEEDED by elogind
1985 int cg_slice_to_path(const char *unit, char **ret) {
1986 _cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
1993 if (streq(unit, SPECIAL_ROOT_SLICE)) {
2003 if (!unit_name_is_valid(unit, UNIT_NAME_PLAIN))
2006 if (!endswith(unit, ".slice"))
2009 r = unit_name_to_prefix(unit, &p);
2013 dash = strchr(p, '-');
2015 /* Don't allow initial dashes */
2020 _cleanup_free_ char *escaped = NULL;
2021 char n[dash - p + sizeof(".slice")];
2023 /* Don't allow trailing or double dashes */
2024 if (dash[1] == 0 || dash[1] == '-')
2027 strcpy(stpncpy(n, p, dash - p), ".slice");
2028 if (!unit_name_is_valid(n, UNIT_NAME_PLAIN))
2031 escaped = cg_escape(n);
2035 if (!strextend(&s, escaped, "/", NULL))
2038 dash = strchr(dash+1, '-');
2041 e = cg_escape(unit);
2045 if (!strextend(&s, e, NULL))
2055 int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
2056 _cleanup_free_ char *p = NULL;
2059 r = cg_get_path(controller, path, attribute, &p);
2063 return write_string_file(p, value, 0);
2066 int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) {
2067 _cleanup_free_ char *p = NULL;
2070 r = cg_get_path(controller, path, attribute, &p);
2074 return read_one_line_file(p, ret);
2077 #if 0 /// UNNEEDED by elogind
2078 int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, const char **keys, char **values) {
2079 _cleanup_free_ char *filename = NULL, *content = NULL;
2083 for (i = 0; keys[i]; i++)
2086 r = cg_get_path(controller, path, attribute, &filename);
2090 r = read_full_file(filename, &content, NULL);
2095 while ((line = strsep(&p, "\n"))) {
2098 key = strsep(&line, " ");
2100 for (i = 0; keys[i]; i++) {
2101 if (streq(key, keys[i])) {
2102 values[i] = strdup(line);
2108 for (i = 0; keys[i]; i++) {
2110 for (i = 0; keys[i]; i++) {
2121 int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) {
2125 /* This one will create a cgroup in our private tree, but also
2126 * duplicate it in the trees specified in mask, and remove it
2129 /* First create the cgroup in our own hierarchy. */
2130 r = cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
2134 /* If we are in the unified hierarchy, we are done now */
2135 r = cg_all_unified();
2141 /* Otherwise, do the same in the other hierarchies */
2142 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2143 CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
2146 n = cgroup_controller_to_string(c);
2149 (void) cg_create(n, path);
2150 else if (supported & bit)
2151 (void) cg_trim(n, path, true);
2157 int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
2161 r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
2165 r = cg_all_unified();
2171 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2172 CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
2173 const char *p = NULL;
2175 if (!(supported & bit))
2179 p = path_callback(bit, userdata);
2184 (void) cg_attach_fallback(cgroup_controller_to_string(c), p, pid);
2190 int cg_attach_many_everywhere(CGroupMask supported, const char *path, Set* pids, cg_migrate_callback_t path_callback, void *userdata) {
2195 SET_FOREACH(pidp, pids, i) {
2196 pid_t pid = PTR_TO_PID(pidp);
2199 q = cg_attach_everywhere(supported, path, pid, path_callback, userdata);
2200 if (q < 0 && r >= 0)
2207 int cg_migrate_everywhere(CGroupMask supported, const char *from, const char *to, cg_migrate_callback_t to_callback, void *userdata) {
2211 if (!path_equal(from, to)) {
2212 r = cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, from, SYSTEMD_CGROUP_CONTROLLER, to, CGROUP_REMOVE);
2217 q = cg_all_unified();
2223 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2224 CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
2225 const char *p = NULL;
2227 if (!(supported & bit))
2231 p = to_callback(bit, userdata);
2236 (void) cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, to, cgroup_controller_to_string(c), p, 0);
2242 int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) {
2246 r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
2250 q = cg_all_unified();
2256 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2257 CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
2259 if (!(supported & bit))
2262 (void) cg_trim(cgroup_controller_to_string(c), path, delete_root);
2269 int cg_mask_to_string(CGroupMask mask, char **ret) {
2270 const char *controllers[_CGROUP_CONTROLLER_MAX + 1];
2282 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2284 if (!(mask & CGROUP_CONTROLLER_TO_MASK(c)))
2287 controllers[i++] = cgroup_controller_to_string(c);
2288 controllers[i] = NULL;
2291 s = strv_join((char **)controllers, NULL);
2299 int cg_mask_from_string(const char *value, CGroupMask *mask) {
2304 _cleanup_free_ char *n = NULL;
2308 r = extract_first_word(&value, &n, NULL, 0);
2314 v = cgroup_controller_from_string(n);
2318 *mask |= CGROUP_CONTROLLER_TO_MASK(v);
2323 int cg_mask_supported(CGroupMask *ret) {
2324 CGroupMask mask = 0;
2327 /* Determines the mask of supported cgroup controllers. Only
2328 * includes controllers we can make sense of and that are
2329 * actually accessible. */
2331 r = cg_all_unified();
2335 _cleanup_free_ char *root = NULL, *controllers = NULL, *path = NULL;
2337 /* In the unified hierarchy we can read the supported
2338 * and accessible controllers from a the top-level
2339 * cgroup attribute */
2341 r = cg_get_root_path(&root);
2345 r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path);
2349 r = read_one_line_file(path, &controllers);
2353 r = cg_mask_from_string(controllers, &mask);
2357 /* Currently, we support the cpu, memory, io and pids
2358 * controller in the unified hierarchy, mask
2359 * everything else off. */
2360 mask &= CGROUP_MASK_CPU | CGROUP_MASK_MEMORY | CGROUP_MASK_IO | CGROUP_MASK_PIDS;
2365 /* In the legacy hierarchy, we check whether which
2366 * hierarchies are mounted. */
2368 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2371 n = cgroup_controller_to_string(c);
2372 if (controller_is_accessible(n) >= 0)
2373 mask |= CGROUP_CONTROLLER_TO_MASK(c);
2381 #if 0 /// UNNEEDED by elogind
2382 int cg_kernel_controllers(Set *controllers) {
2383 _cleanup_fclose_ FILE *f = NULL;
2387 assert(controllers);
2389 /* Determines the full list of kernel-known controllers. Might
2390 * include controllers we don't actually support, arbitrary
2391 * named hierarchies and controllers that aren't currently
2392 * accessible (because not mounted). */
2394 f = fopen("/proc/cgroups", "re");
2396 if (errno == ENOENT)
2401 /* Ignore the header line */
2402 (void) fgets(buf, sizeof(buf), f);
2409 if (fscanf(f, "%ms %*i %*i %i", &controller, &enabled) != 2) {
2414 if (ferror(f) && errno > 0)
2425 if (!cg_controller_is_valid(controller)) {
2430 r = set_consume(controllers, controller);
2439 static thread_local CGroupUnified unified_cache = CGROUP_UNIFIED_UNKNOWN;
2441 /* The hybrid mode was initially implemented in v232 and simply mounted cgroup v2 on /sys/fs/cgroup/systemd. This
2442 * unfortunately broke other tools (such as docker) which expected the v1 "name=systemd" hierarchy on
2443 * /sys/fs/cgroup/systemd. From v233 and on, the hybrid mode mountnbs v2 on /sys/fs/cgroup/unified and maintains
2444 * "name=systemd" hierarchy on /sys/fs/cgroup/systemd for compatibility with other tools.
2446 * To keep live upgrade working, we detect and support v232 layout. When v232 layout is detected, to keep cgroup v2
2447 * process management but disable the compat dual layout, we return %true on
2448 * cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) and %false on cg_hybrid_unified().
2450 static thread_local bool unified_systemd_v232;
2452 static int cg_unified_update(void) {
2456 /* Checks if we support the unified hierarchy. Returns an
2457 * error when the cgroup hierarchies aren't mounted yet or we
2458 * have any other trouble determining if the unified hierarchy
2461 if (unified_cache >= CGROUP_UNIFIED_NONE)
2464 if (statfs("/sys/fs/cgroup/", &fs) < 0)
2467 #if 0 /// UNNEEDED by elogind
2468 if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
2469 unified_cache = CGROUP_UNIFIED_ALL;
2470 else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
2471 if (statfs("/sys/fs/cgroup/unified/", &fs) == 0 &&
2472 F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
2473 unified_cache = CGROUP_UNIFIED_SYSTEMD;
2474 unified_systemd_v232 = false;
2475 } else if (statfs("/sys/fs/cgroup/systemd/", &fs) == 0 &&
2476 F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
2477 unified_cache = CGROUP_UNIFIED_SYSTEMD;
2478 unified_systemd_v232 = true;
2480 if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0)
2482 if (!F_TYPE_EQUAL(fs.f_type, CGROUP_SUPER_MAGIC))
2484 unified_cache = CGROUP_UNIFIED_NONE;
2489 /* elogind can not support the unified hierarchy as a controller,
2490 * so always assume a classical hierarchy.
2491 * If, and only *if*, someone really wants to substitute systemd-login
2492 * in an environment managed by systemd with elogind, we might have to
2493 * add such a support. */
2494 unified_cache = CGROUP_UNIFIED_NONE;
2500 int cg_unified_controller(const char *controller) {
2503 r = cg_unified_update();
2507 if (unified_cache == CGROUP_UNIFIED_NONE)
2510 if (unified_cache >= CGROUP_UNIFIED_ALL)
2513 return streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER);
2516 int cg_all_unified(void) {
2519 r = cg_unified_update();
2523 return unified_cache >= CGROUP_UNIFIED_ALL;
2526 int cg_hybrid_unified(void) {
2529 r = cg_unified_update();
2533 return unified_cache == CGROUP_UNIFIED_SYSTEMD && !unified_systemd_v232;
2536 int cg_unified_flush(void) {
2537 unified_cache = CGROUP_UNIFIED_UNKNOWN;
2539 return cg_unified_update();
2542 #if 0 /// UNNEEDED by elogind
2543 int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
2544 _cleanup_free_ char *fs = NULL;
2553 r = cg_all_unified();
2556 if (r == 0) /* on the legacy hiearchy there's no joining of controllers defined */
2559 r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, p, "cgroup.subtree_control", &fs);
2563 for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
2564 CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c);
2567 if (!(supported & bit))
2570 n = cgroup_controller_to_string(c);
2572 char s[1 + strlen(n) + 1];
2574 s[0] = mask & bit ? '+' : '-';
2577 r = write_string_file(fs, s, 0);
2579 log_debug_errno(r, "Failed to enable controller %s for %s (%s): %m", n, p, fs);
2586 bool cg_is_unified_wanted(void) {
2587 static thread_local int wanted = -1;
2590 const bool is_default = DEFAULT_HIERARCHY == CGROUP_UNIFIED_ALL;
2592 /* If we have a cached value, return that. */
2596 /* If the hierarchy is already mounted, then follow whatever
2597 * was chosen for it. */
2598 if (cg_unified_flush() >= 0)
2599 return (wanted = unified_cache >= CGROUP_UNIFIED_ALL);
2601 /* Otherwise, let's see what the kernel command line has to say.
2602 * Since checking is expensive, cache a non-error result. */
2603 r = proc_cmdline_get_bool("systemd.unified_cgroup_hierarchy", &b);
2605 return (wanted = r > 0 ? b : is_default);
2608 bool cg_is_legacy_wanted(void) {
2609 static thread_local int wanted = -1;
2611 /* If we have a cached value, return that. */
2615 /* Check if we have cgroups2 already mounted. */
2616 if (cg_unified_flush() >= 0 &&
2617 unified_cache == CGROUP_UNIFIED_ALL)
2618 return (wanted = false);
2620 /* Otherwise, assume that at least partial legacy is wanted,
2621 * since cgroups2 should already be mounted at this point. */
2622 return (wanted = true);
2625 bool cg_is_hybrid_wanted(void) {
2626 static thread_local int wanted = -1;
2629 const bool is_default = DEFAULT_HIERARCHY >= CGROUP_UNIFIED_SYSTEMD;
2630 /* We default to true if the default is "hybrid", obviously,
2631 * but also when the default is "unified", because if we get
2632 * called, it means that unified hierarchy was not mounted. */
2634 /* If we have a cached value, return that. */
2638 /* If the hierarchy is already mounted, then follow whatever
2639 * was chosen for it. */
2640 if (cg_unified_flush() >= 0 &&
2641 unified_cache == CGROUP_UNIFIED_ALL)
2642 return (wanted = false);
2644 /* Otherwise, let's see what the kernel command line has to say.
2645 * Since checking is expensive, cache a non-error result. */
2646 r = proc_cmdline_get_bool("systemd.legacy_systemd_cgroup_controller", &b);
2648 /* The meaning of the kernel option is reversed wrt. to the return value
2649 * of this function, hence the negation. */
2650 return (wanted = r > 0 ? !b : is_default);
2653 bool cg_is_unified_wanted(void) {
2656 bool cg_is_legacy_wanted(void) {
2659 bool cg_is_hybrid_wanted(void) {
2664 #if 0 /// UNNEEDED by elogind
2665 int cg_weight_parse(const char *s, uint64_t *ret) {
2670 *ret = CGROUP_WEIGHT_INVALID;
2674 r = safe_atou64(s, &u);
2678 if (u < CGROUP_WEIGHT_MIN || u > CGROUP_WEIGHT_MAX)
2685 const uint64_t cgroup_io_limit_defaults[_CGROUP_IO_LIMIT_TYPE_MAX] = {
2686 [CGROUP_IO_RBPS_MAX] = CGROUP_LIMIT_MAX,
2687 [CGROUP_IO_WBPS_MAX] = CGROUP_LIMIT_MAX,
2688 [CGROUP_IO_RIOPS_MAX] = CGROUP_LIMIT_MAX,
2689 [CGROUP_IO_WIOPS_MAX] = CGROUP_LIMIT_MAX,
2692 static const char* const cgroup_io_limit_type_table[_CGROUP_IO_LIMIT_TYPE_MAX] = {
2693 [CGROUP_IO_RBPS_MAX] = "IOReadBandwidthMax",
2694 [CGROUP_IO_WBPS_MAX] = "IOWriteBandwidthMax",
2695 [CGROUP_IO_RIOPS_MAX] = "IOReadIOPSMax",
2696 [CGROUP_IO_WIOPS_MAX] = "IOWriteIOPSMax",
2699 DEFINE_STRING_TABLE_LOOKUP(cgroup_io_limit_type, CGroupIOLimitType);
2701 int cg_cpu_shares_parse(const char *s, uint64_t *ret) {
2706 *ret = CGROUP_CPU_SHARES_INVALID;
2710 r = safe_atou64(s, &u);
2714 if (u < CGROUP_CPU_SHARES_MIN || u > CGROUP_CPU_SHARES_MAX)
2721 int cg_blkio_weight_parse(const char *s, uint64_t *ret) {
2726 *ret = CGROUP_BLKIO_WEIGHT_INVALID;
2730 r = safe_atou64(s, &u);
2734 if (u < CGROUP_BLKIO_WEIGHT_MIN || u > CGROUP_BLKIO_WEIGHT_MAX)
2742 bool is_cgroup_fs(const struct statfs *s) {
2743 return is_fs_type(s, CGROUP_SUPER_MAGIC) ||
2744 is_fs_type(s, CGROUP2_SUPER_MAGIC);
2747 bool fd_is_cgroup_fs(int fd) {
2750 if (fstatfs(fd, &s) < 0)
2753 return is_cgroup_fs(&s);
2756 static const char *cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = {
2757 [CGROUP_CONTROLLER_CPU] = "cpu",
2758 [CGROUP_CONTROLLER_CPUACCT] = "cpuacct",
2759 [CGROUP_CONTROLLER_IO] = "io",
2760 [CGROUP_CONTROLLER_BLKIO] = "blkio",
2761 [CGROUP_CONTROLLER_MEMORY] = "memory",
2762 [CGROUP_CONTROLLER_DEVICES] = "devices",
2763 [CGROUP_CONTROLLER_PIDS] = "pids",
2766 DEFINE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController);