#include #include #include #include #include /* Ugly, I know... */ #include "../src/tools/tools-common.h" struct cgroup_group_spec *cgroup_list[CG_HIER_MAX]; int main(int argc, char **argv) { int ret; int i, j; char *parent; char controllers[PATH_MAX]; struct cgroup *cgroup; struct cgroup_controller *cgc; ret = cgroup_init(); if (ret) { fprintf(stderr, "cgroup_init failed with %s\n", cgroup_strerror(ret)); exit(1); } if (argc < 2) { fprintf(stderr, "at least one argument is expected\n"); printf("Usage: %s : ... \n", argv[0]); exit(1); } for (i = 1; i < argc; i++) { ret = parse_cgroup_spec(cgroup_list, argv[i]); if (ret) { fprintf(stderr, "cannot parse %s\n", argv[i]); exit(1); } } for (i = 0; i < CG_HIER_MAX; i++) { if (!cgroup_list[i]) break; cgroup = cgroup_new_cgroup(cgroup_list[i]->path); if (cgroup == NULL) { fprintf(stderr, "cannot create new cgroup for %s\n", argv[i]); exit(1); } memset(controllers, 0, sizeof(controllers)); for (j = 0; j < CG_CONTROLLER_MAX; j++) { if (cgroup_list[i]->controllers[j] == NULL) break; strncat(controllers, cgroup_list[i]->controllers[j], sizeof(controllers) - strlen(controllers)); strncat(controllers, ",", sizeof(controllers) - strlen(controllers)); cgc = cgroup_add_controller(cgroup, cgroup_list[i]->controllers[j]); if (cgc == NULL) { fprintf(stderr, "cannot add %s to %s\n", cgroup_list[i]->path, cgroup_list[i]->controllers[j]); exit(1); } } ret = cgroup_find_parent(cgroup, &parent); printf("Parent of %s:%s is: %s (%d)\n", controllers, cgroup_list[i]->path, parent, ret); free(parent); cgroup_free_group_spec(cgroup_list[i]); cgroup_free(&cgroup); } return 0; }