Exemple #1
0
/*
 * for each mounted cgroup, create a cgroup for the container
 */
int lxc_cgroup_create(const char *name, pid_t pid)
{
	struct mntent *mntent;
	FILE *file = NULL;
	int err = -1;

	file = setmntent(MTAB, "r");
	if (!file) {
		SYSERROR("failed to open %s", MTAB);
		return -1;
	}

	while ((mntent = getmntent(file))) {

		DEBUG("checking '%s' (%s)", mntent->mnt_dir, mntent->mnt_type);

		if (!strcmp(mntent->mnt_type, "cgroup")) {

			INFO("found cgroup mounted at '%s'", mntent->mnt_dir);
			err = lxc_one_cgroup_create(name, mntent, pid);
			if (err)
				goto out;
		}
	};

out:
	endmntent(file);
	return err;
}
Exemple #2
0
/*
 * for each mounted cgroup, create a cgroup for the container and attach a pid
 */
int lxc_cgroup_create(const char *name, pid_t pid)
{
	struct mntent *mntent;
	FILE *file = NULL;
	int err = -1;
	int found = 0;

	file = setmntent(MTAB, "r");
	if (!file) {
		SYSERROR("failed to open %s", MTAB);
		return -1;
	}

	while ((mntent = getmntent(file))) {
		DEBUG("checking '%s' (%s)", mntent->mnt_dir, mntent->mnt_type);

		if (strcmp(mntent->mnt_type, "cgroup"))
			continue;
		if (!mount_has_subsystem(mntent))
			continue;

		INFO("[%d] found cgroup mounted at '%s',opts='%s'",
		     ++found, mntent->mnt_dir, mntent->mnt_opts);

		err = lxc_one_cgroup_create(name, mntent, pid);
		if (err)
			goto out;

		err = lxc_one_cgroup_attach(name, mntent, pid);
		if (err)
			goto out;
	};

	if (!found)
		ERROR("No cgroup mounted on the system");

out:
	endmntent(file);
	return err;
}