X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Fcgroup-util.c;h=ec2c529914d32168689e2222dc5f504407ecb06b;hp=40e09d6f90605741351531363fe6a208ec3adae9;hb=9742b1e43855b1599bd52ff95af995d9a9d35eac;hpb=a1002c6e2e7933c03aa4f49bdbce31e246ab589d diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 40e09d6f9..ec2c52991 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2265,6 +2265,60 @@ int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) } #endif // 0 +int cg_mask_to_string(CGroupMask mask, char **ret) { + const char *controllers[_CGROUP_CONTROLLER_MAX + 1]; + CGroupController c; + int i = 0; + char *s; + + assert(ret); + + if (mask == 0) { + *ret = NULL; + return 0; + } + + for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { + + if (!(mask & CGROUP_CONTROLLER_TO_MASK(c))) + continue; + + controllers[i++] = cgroup_controller_to_string(c); + controllers[i] = NULL; + } + + s = strv_join((char **)controllers, NULL); + if (!s) + return -ENOMEM; + + *ret = s; + return 0; +} + +int cg_mask_from_string(const char *value, CGroupMask *mask) { + assert(mask); + assert(value); + + for (;;) { + _cleanup_free_ char *n = NULL; + CGroupController v; + int r; + + r = extract_first_word(&value, &n, NULL, 0); + if (r < 0) + return r; + if (r == 0) + break; + + v = cgroup_controller_from_string(n); + if (v < 0) + continue; + + *mask |= CGROUP_CONTROLLER_TO_MASK(v); + } + return 0; +} + int cg_mask_supported(CGroupMask *ret) { CGroupMask mask = 0; int r; @@ -2278,7 +2332,6 @@ int cg_mask_supported(CGroupMask *ret) { return r; if (r > 0) { _cleanup_free_ char *root = NULL, *controllers = NULL, *path = NULL; - const char *c; /* In the unified hierarchy we can read the supported * and accessible controllers from a the top-level @@ -2296,23 +2349,9 @@ int cg_mask_supported(CGroupMask *ret) { if (r < 0) return r; - c = controllers; - for (;;) { - _cleanup_free_ char *n = NULL; - CGroupController v; - - r = extract_first_word(&c, &n, NULL, 0); - if (r < 0) - return r; - if (r == 0) - break; - - v = cgroup_controller_from_string(n); - if (v < 0) - continue; - - mask |= CGROUP_CONTROLLER_TO_MASK(v); - } + r = cg_mask_from_string(controllers, &mask); + if (r < 0) + return r; /* Currently, we support the cpu, memory, io and pids * controller in the unified hierarchy, mask @@ -2483,7 +2522,6 @@ int cg_all_unified(void) { return unified_cache >= CGROUP_UNIFIED_ALL; } -#if 0 /// UNNEEDED by elogind int cg_hybrid_unified(void) { int r; @@ -2500,6 +2538,7 @@ int cg_unified_flush(void) { return cg_unified_update(); } +#if 0 /// UNNEEDED by elogind int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) { _cleanup_free_ char *fs = NULL; CGroupController c; @@ -2605,18 +2644,19 @@ bool cg_is_hybrid_wanted(void) { * Since checking is expensive, cache a non-error result. */ r = proc_cmdline_get_bool("systemd.legacy_systemd_cgroup_controller", &b); + /* The meaning of the kernel option is reversed wrt. to the return value + * of this function, hence the negation. */ + return (wanted = r > 0 ? !b : is_default); +} #else +bool cg_is_unified_wanted(void) { + return false; +} bool cg_is_legacy_wanted(void) { return true; - /* The meaning of the kernel option is reversed wrt. to the return value - * of this function, hence the negation. */ - return (wanted = r > 0 ? !b : false); - return (wanted = r > 0 ? b : false); } - -bool cg_is_legacy_systemd_controller_wanted(void) { - return cg_is_legacy_wanted() && !cg_is_unified_systemd_controller_wanted(); - return (wanted = r > 0 ? !b : is_default); +bool cg_is_hybrid_wanted(void) { + return false; } #endif // 0