Skip to content

Commit c1fbf42

Browse files
committed
stress-cgroup: read cgroup files from directory contents
Don't use hard coded cgroup file list, use the files from the directory contents. Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent e13b254 commit c1fbf42

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

stress-cgroup.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -266,30 +266,22 @@ static void stress_cgroup_controllers(const char *realpathname)
266266
*/
267267
static void stress_cgroup_read_files(const char *realpathname)
268268
{
269-
static const char * const filenames[] = {
270-
"cgroup.type",
271-
"cgroup.procs",
272-
"cgroup.threads",
273-
"cgroup.controllers",
274-
"cgroup.subtree_control",
275-
"cgroup.events",
276-
"cgroup.max.descendants",
277-
"cgroup.max.depth",
278-
"cgroup.stat",
279-
"cgroup.freeze",
280-
"cgroup.kill",
281-
"cgroup.pressure",
282-
"irq.pressure",
283-
};
284-
285-
size_t i;
286-
287-
for (i = 0; i < SIZEOF_ARRAY(filenames); i++) {
288-
char path[PATH_MAX + 32];
289-
290-
(void)snprintf(path, sizeof(path), "%s/%s", realpathname, filenames[i]);
291-
stress_cgroup_read(path);
269+
DIR *dir;
270+
struct dirent *de;
271+
272+
dir = opendir(realpathname);
273+
if (!dir)
274+
return;
275+
276+
while ((de = readdir(dir)) != NULL) {
277+
if (de->d_type == DT_REG) {
278+
char path[PATH_MAX + 256];
279+
280+
(void)snprintf(path, sizeof(path), "%s/%s", realpathname, de->d_name);
281+
stress_cgroup_read(path);
282+
}
292283
}
284+
(void)closedir(dir);
293285
}
294286

295287
/*

0 commit comments

Comments
 (0)