Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cgroup01.c « static « zdtm « test - github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f0d00f209eb87ba2fcd424b02b3ef581008db624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include "zdtmtst.h"

const char *test_doc	= "Check that empty cgroups are preserved";
const char *test_author	= "Tycho Andersen <tycho.andersen@canonical.com>";

char *dirname;
TEST_OPTION(dirname, string, "cgroup directory name", 1);
static const char *cgname = "zdtmtst";
static const char *subname = "subcg01";
static const char *empty = "empty";

int main(int argc, char **argv)
{
	int cgfd, l, ret = 1, i;
	char aux[1024], paux[1024];
	FILE *cgf;
	struct stat st;

	test_init(argc, argv);

	if (mkdir(dirname, 0700) < 0) {
		pr_perror("Can't make dir");
		goto out;
	}

	sprintf(aux, "none,name=%s", cgname);
	if (mount("none", dirname, "cgroup", 0, aux)) {
		pr_perror("Can't mount cgroups");
		goto out_rd;
	}

	sprintf(paux, "%s/%s", dirname, subname);
	mkdir(paux, 0600);

	l = sprintf(aux, "%d", getpid());
	sprintf(paux, "%s/%s/tasks", dirname, subname);

	cgfd = open(paux, O_WRONLY);
	if (cgfd < 0) {
		pr_perror("Can't open tasks");
		goto out_rs;
	}

	l = write(cgfd, aux, l);
	close(cgfd);

	if (l < 0) {
		pr_perror("Can't move self to subcg");
		goto out_rs;
	}

	for (i = 0; i < 2; i++) {
		sprintf(paux, "%s/%s/%s.%d", dirname, subname, empty, i);
		if (mkdir(paux, 0600)) {
			pr_perror("mkdir %s", paux);
			goto out_rs;
		}
	}

	test_daemon();
	test_waitsig();

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

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

		s = strstr(paux, cgname);
		if (!s)
			continue;

		sscanf(paux, "%*d %*d %*d:%*d %*s %s", aux);
		test_msg("found cgroup at %s\n", aux);

		for (i = 0; i < 2; i++) {
			ssprintf(paux, "%s/%s/%s.%d", aux, subname, empty, i);

			if (stat(paux, &st)) {
				fail("couldn't stat %s", paux);
				ret = -1;
				goto out_close;
			}

			if (!S_ISDIR(st.st_mode)) {
				fail("%s is not a directory", paux);
				ret = -1;
				goto out_close;
			}
		}

		pass();
		ret = 0;
		goto out_close;
	}

	fail("empty cgroup not found!");

out_close:
	fclose(cgf);
out_rs:
	umount(dirname);
out_rd:
	rmdir(dirname);
out:
	return ret;
}