Ejemplo n.º 1
0
/*
 * inlist is a comma-delimited list of cgroups;  so is checklist.  Return
 * true if any member of inlist is in checklist.
 */
static bool any_in_comma_list(const char *inlist, const char *checklist)
{
	char *tmp = alloca(strlen(inlist) + 1), *tok, *saveptr = NULL;

	strcpy(tmp, inlist);
	for (tok = strtok_r(tmp, ",", &saveptr); tok; tok = strtok_r(NULL, ",", &saveptr)) {
		if (in_comma_list(tok, checklist))
			return true;
	}

	return false;
}
Ejemplo n.º 2
0
/* do we need to do any massaging here?  I'm not sure... */
char *find_mounted_controller(const char *controller)
{
	int i;

	for (i = 0; i < num_hierarchies; i++) {
		if (!hierarchies[i])
			continue;
		if (strcmp(hierarchies[i], controller) == 0)
			return hierarchies[i];
		if (in_comma_list(controller, hierarchies[i]))
			return hierarchies[i];
	}

	return NULL;
}
Ejemplo n.º 3
0
/*
 * If /etc/lxc/lxc.conf specifies lxc.cgroup.use = "freezer,memory",
 * then clear out any other subsystems, and make sure that freezer
 * and memory are both enabled
 */
static bool verify_and_prune(const char *cgroup_use)
{
	const char *p;
	char *e;
	int i, j;

	for (p = cgroup_use; p && *p; p = e + 1) {
		e = strchr(p, ',');
		if (e)
			*e = '\0';

		if (!in_subsystem_list(p)) {
			ERROR("Controller %s required by lxc.cgroup.use but not available\n", p);
			return false;
		}

		if (e)
			*e = ',';
		if (!e)
			break;
	}

	for (i = 0; i < nr_subsystems;) {
		if (in_comma_list(subsystems[i], cgroup_use)) {
			i++;
			continue;
		}
		free(subsystems[i]);
		for (j = i;  j < nr_subsystems-1; j++)
			subsystems[j] = subsystems[j+1];
		subsystems[nr_subsystems-1] = NULL;
		nr_subsystems--;
	}

	return true;
}