コード例 #1
0
ファイル: cgroup03.c プロジェクト: 0x7f454c46/criu
int main(int argc, char **argv)
{
	int ret = -1;
	char path[PATH_MAX];

	test_init(argc, argv);

	if (mount_and_add(cgname, "test") < 0)
		return -1;

	sprintf(path, "%s/%s/test", dirname, cgname);
	if (chownmod(path, O_DIRECTORY) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/notify_on_release", dirname, cgname);
	if (chownmod(path, O_RDWR) < 0)
		goto out_umount;


	sprintf(path, "%s/%s/test/cgroup.procs", dirname, cgname);
	if (chownmod(path, O_RDWR) < 0)
		goto out_umount;

	test_daemon();
	test_waitsig();

	sprintf(path, "%s/%s/test", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/notify_on_release", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/cgroup.procs", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	pass();
	ret = 0;

out_umount:
	sprintf(path, "%s/%s/test", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/%s", dirname, cgname);
	umount(path);
	rmdir(path);
	rmdir(dirname);
	return ret;
}
コード例 #2
0
ファイル: cgroup04.c プロジェクト: NoMore201/criu
int main(int argc, char **argv)
{
	int ret = -1, i;
	char buf[1024], path[PATH_MAX];
	struct stat sb;

	char *dev_allow[] = {
		"c *:* m",
		"b *:* m",
		"c 1:3 rwm",
		"c 1:5 rwm",
		"c 1:7 rwm",
		"c 5:0 rwm",
		"c 5:2 rwm",
		"c 1:8 rwm",
		"c 1:9 rwm",
		"c 136:* rwm",
		"c 10:229 rwm",
	};

	test_init(argc, argv);

	if (mount_and_add("devices", cgname, "devices.deny", "a") < 0)
		goto out;

	/* need to allow /dev/null for restore */
	sprintf(path, "%s/devices/%s/devices.allow", dirname, cgname);
	for (i = 0; i < ARRAY_SIZE(dev_allow); i++) {
		if (write_value(path, dev_allow[i]) < 0)
			goto out;
	}

	if (mount_and_add("memory", cgname, "memory.limit_in_bytes", "268435456") < 0)
		goto out;

	test_daemon();
	test_waitsig();

	buf[0] = 0;
	for (i = 0; i < ARRAY_SIZE(dev_allow); i++) {
		strcat(buf, dev_allow[i]);
		strcat(buf, "\n");
	}

	sprintf(path, "%s/devices/%s/devices.list", dirname, cgname);
	if (!checkval(path, buf)) {
		fail();
		goto out;
	}

	sprintf(path, "%s/memory/%s/memory.limit_in_bytes", dirname, cgname);
	if (!checkval(path, "268435456\n")) {
		fail();
		goto out;
	}

	sprintf(path, "%s/devices/%s/special_prop_check", dirname, cgname);
	if (stat(path, &sb) < 0) {
		fail("special_prop_check doesn't exist?");
		goto out;
	}

	if (!S_ISDIR(sb.st_mode)) {
		fail("special_prop_check not a directory?");
		goto out;
	}

	pass();
	ret = 0;
out:
	sprintf(path, "%s/devices/%s/special_prop_check", dirname, cgname);
	rmdir(path);

	sprintf(path, "%s/devices/%s", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/devices", dirname);
	umount(path);

	sprintf(path, "%s/memory/%s", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/memory", dirname);
	umount(path);

	return ret;
}
コード例 #3
0
ファイル: cgroupns.c プロジェクト: southerngs/criu
int main(int argc, char **argv)
{
	int ret = -1, sk_pair[2], sk, status;
	char path[PATH_MAX], c;
	pid_t pid;

	test_init(argc, argv);

	if (mount_and_add(cgname, "test") < 0)
		return -1;

	if (socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair)) {
		pr_perror("socketpair");
		goto out;
	}

	pid = fork();
	if (pid < 0) {
		pr_perror("fork failed");
		goto out;
	}

	if (pid == 0) {
		close(sk_pair[0]);
		if (unshare_cgns_and_wait(sk_pair+1))
			exit(1);
		exit(0);
	}

	close(sk_pair[1]);
	sk = sk_pair[0];

	if ((ret = read(sk, &c, 1)) != 1) {
		pr_perror("read %d", ret);
		goto out;
	}

	test_daemon();
	test_waitsig();

	sprintf(path, "name=%s", cgname);

	/* first check that the task is in zdtmtst:/test */
	if (!pid_in_cgroup(pid, path, "/test")) {
		fail("pid not in cgroup /test");
		goto out;
	}

	/* now have the task check that it is in / */
	if (write(sk, &c, 1) != 1) {
		pr_perror("write");
		goto out;
	}

	if (pid != waitpid(pid, &status, 0)) {
		pr_perror("waitpid");
		goto out;
	}

	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
		fail("exit status %s\n", status);
		goto out;
	}

	pass();
	ret = 0;
out:
	sprintf(path, "%s/%s/test", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/%s", dirname, cgname);
	umount(path);
	rmdir(path);
	rmdir(dirname);
	return ret;
}
コード例 #4
0
ファイル: cgroupns.c プロジェクト: 0x7f454c46/criu-1
int main(int argc, char **argv)
{
	int ret = -1, fd, status;
	char path[PATH_MAX];
	pid_t pid;

	if (!getenv("ZDTM_NEWNS")) {
		if (mount_and_add(cgname, "test") < 0)
			return -1;

		if (unshare(CLONE_NEWCGROUP) < 0) {
			pr_perror("unshare");
			goto out;
		}
	}

	test_init(argc, argv);

	test_daemon();
	test_waitsig();

	sprintf(path, "name=%s", cgname);

	/* first check that the task is in zdtmtst:/ */
	if (!pid_in_cgroup(getpid(), path, "/")) {
		fail("pid not in cgroup /");
		goto out;
	}

	/* now check that the task is in the right place in a ns by setnsing to
	 * someone else's ns and looking there.
	 */
	pid = fork();
	if (pid < 0) {
		pr_perror("fork");
		goto out;
	}

	if (pid == 0) {
		sprintf(path, "/proc/%d/ns/cgroup", 1);
		fd = open(path, O_RDONLY);
		if (fd < 0) {
			pr_perror("open");
			exit(1);
		}

		ret = setns(fd, CLONE_NEWCGROUP);
		close(fd);
		if (ret < 0) {
			pr_perror("setns");
			exit(1);
		}

		sprintf(path, "name=%s", cgname);
		if (!pid_in_cgroup(getppid(), path, "/test")) {
			fail("pid not in cgroup %s", path);
			exit(1);
		}

		exit(0);
	}

	if (pid != waitpid(pid, &status, 0)) {
		pr_err("wrong pid");
		goto out;
	}

	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
		pr_err("got bad exit status %d\n", status);
		goto out;
	}

	ret = 0;
	pass();

out:
	sprintf(path, "%s/%s/test", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/%s", dirname, cgname);
	umount(path);
	rmdir(path);
	rmdir(dirname);
	return ret;
}
コード例 #5
0
ファイル: cgroup02.c プロジェクト: balamark/criu
int main(int argc, char **argv)
{
	FILE *cgf;
	bool found_zdtmtstroot = false, found_newroot = false;
	char paux[1024];
	int ret = -1;

	test_init(argc, argv);

	if (mount_and_add(cgname, subname))
		goto out;
	if (mount_and_add(cgname2, subname)) {
		sprintf(paux, "%s/%s", dirname, cgname);
		umount(paux);
		rmdir(paux);
		goto out;
	}

	test_daemon();
	test_waitsig();

	cgf = fopen("/proc/self/mountinfo", "r");
	if (cgf == NULL) {
		fail("No mountinfo file");
		goto out_umount;
	}

	while (fgets(paux, sizeof(paux), cgf)) {
		char *s;

		s = strstr(paux, cgname);
		if (s && test_exists(paux, "zdtmtstroot")) {
			found_zdtmtstroot = true;
		}

		s = strstr(paux, cgname2);
		if (s && test_exists(paux, "newroot")) {
			found_newroot = true;
		}
	}

	if (!found_zdtmtstroot) {
		fail("oldroot not rewritten to zdtmtstroot!\n");
		goto out_close;
	}

	if (!found_newroot) {
		fail("oldroot not rewritten to newroot!\n");
		goto out_close;
	}

	pass();
	ret = 0;


out_close:
	fclose(cgf);
out_umount:
	sprintf(paux, "%s/%s", dirname, cgname);
	umount(paux);
	rmdir(paux);

	sprintf(paux, "%s/%s", dirname, cgname2);
	umount(paux);
	rmdir(paux);
out:
	return ret;
}