*/
static bool all_controllers_found(struct cgroup_ops *ops)
{
- char *p;
- char *saveptr = NULL;
+ char **cur;
struct hierarchy **hlist = ops->hierarchies;
if (!controller_found(hlist, "freezer")) {
if (!ops->cgroup_use)
return true;
- for (; (p = strtok_r(ops->cgroup_use, ",", &saveptr)); ops->cgroup_use = NULL)
- if (!controller_found(hlist, p)) {
- ERROR("No %s controller mountpoint found", p);
+ for (cur = ops->cgroup_use; cur && *cur; cur++)
+ if (!controller_found(hlist, *cur)) {
+ ERROR("No %s controller mountpoint found", *cur);
return false;
}
return __cg_unified_setup_limits(ops, &conf->cgroup2);
}
+static bool cgroup_use_wants_controllers(const struct cgroup_ops *ops,
+ char **controllers)
+{
+ char **cur_ctrl, **cur_use;
+
+ if (!ops->cgroup_use)
+ return true;
+
+ for (cur_ctrl = controllers; cur_ctrl && *cur_ctrl; cur_ctrl++) {
+ bool found = false;
+
+ for (cur_use = ops->cgroup_use; cur_use && *cur_use; cur_use++) {
+ if (strcmp(*cur_use, *cur_ctrl) != 0)
+ continue;
+
+ found = true;
+ break;
+ }
+
+ if (found)
+ continue;
+
+ return false;
+ }
+
+ return true;
+}
+
/* At startup, parse_hierarchies finds all the info we need about cgroup
* mountpoints and current cgroups, and stores it in @d.
*/
}
}
+ /* Exclude all controllers that cgroup use does not want. */
+ if (!cgroup_use_wants_controllers(ops, controller_list))
+ goto next;
+
new = add_hierarchy(&ops->hierarchies, controller_list, mountpoint, base_cgroup, type);
if (type == CGROUP2_SUPER_MAGIC && !ops->unified)
ops->unified = new;
const char *tmp;
tmp = lxc_global_config_value("lxc.cgroup.use");
- if (tmp)
- ops->cgroup_use = must_copy_string(tmp);
+ if (tmp) {
+ char *chop, *cur, *pin;
+ char *saveptr = NULL;
+
+ pin = must_copy_string(tmp);
+ chop = pin;
+
+ for (; (cur = strtok_r(chop, ",", &saveptr)); chop = NULL)
+ must_append_string(&ops->cgroup_use, cur);
+
+ free(pin);
+ }
ret = cg_unified_init(ops);
if (ret < 0)
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
void cgroup_exit(struct cgroup_ops *ops)
{
+ char **cur;
struct hierarchy **it;
if (!ops)
return;
- free(ops->cgroup_use);
+ for (cur = ops->cgroup_use; cur && *cur; cur++)
+ free(*cur);
+
free(ops->cgroup_pattern);
free(ops->container_cgroup);