}
#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;
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
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
return unified_cache >= CGROUP_UNIFIED_ALL;
}
-#if 0 /// UNNEEDED by elogind
int cg_hybrid_unified(void) {
int r;
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;
* 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