/*
* Change process group as specified on command line.
*/
-static int change_group_path(pid_t pid, struct cgroup_group_spec *cgroup_list[])
+static int change_group_path(pid_t pid, struct cgroup_group_spec *cgrp_list[])
{
int ret = 0;
int i;
for (i = 0; i < CG_HIER_MAX; i++) {
- if (!cgroup_list[i])
+ if (!cgrp_list[i])
break;
- ret = cgroup_change_cgroup_path(cgroup_list[i]->path, pid,
- (const char *const*) cgroup_list[i]->controllers);
+ ret = cgroup_change_cgroup_path(cgrp_list[i]->path, pid,
+ (const char *const*) cgrp_list[i]->controllers);
if (ret) {
err("Error changing group of pid %d: %s\n", pid, cgroup_strerror(ret));
return -1;
int main(int argc, char *argv[])
{
- struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
+ struct cgroup_group_spec *cgrp_list[CG_HIER_MAX];
#ifdef WITH_SYSTEMD
int ignore_default_systemd_delegate_slice = 0;
#endif
int ret = 0, i, exit_code = 0;
int skip_replace_idle = 0;
+ int cgrp_specified = 0;
pid_t scope_pid = -1;
int replace_idle = 0;
- int cg_specified = 0;
int flag = 0;
char *endptr;
pid_t pid;
exit(EXIT_BADARGS);
}
- memset(cgroup_list, 0, sizeof(cgroup_list));
+ memset(cgrp_list, 0, sizeof(cgrp_list));
#ifdef WITH_SYSTEMD
while ((c = getopt_long(argc, argv, "+g:shbr", longopts, NULL)) > 0) {
switch (c) {
exit(0);
break;
case 'g':
- ret = parse_cgroup_spec(cgroup_list, optarg, CG_HIER_MAX);
+ ret = parse_cgroup_spec(cgrp_list, optarg, CG_HIER_MAX);
if (ret) {
err("cgroup controller and path parsing failed\n");
exit(EXIT_BADARGS);
}
- cg_specified = 1;
+ cgrp_specified = 1;
break;
case 's':
flag |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
}
}
- if (cg_specified)
- ret = change_group_path(pid, cgroup_list);
+ if (cgrp_specified)
+ ret = change_group_path(pid, cgrp_list);
else
ret = change_group_based_on_rule(pid);
{
pid_t _scope_pid = -1, scope_pid = -1;
char ctrl_name[CONTROL_NAMELEN_MAX];
- char cgroup_name[FILENAME_MAX];
char scope_name[FILENAME_MAX];
+ char cgrp_name[FILENAME_MAX];
int found_systemd_cgrp = 0;
int found_unified_cgrp = 0;
char buffer[FILENAME_MAX];
/* read according to the cgroup mode */
if (strstr(buffer, "::")) {
snprintf(ctrl_name, CONTROL_NAMELEN_MAX, "unified");
- ret = sscanf(buffer, "%d::%4096s\n", &idx, cgroup_name);
+ ret = sscanf(buffer, "%d::%4096s\n", &idx, cgrp_name);
} else {
- ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgroup_name);
+ ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgrp_name);
}
if (ret != 2 && ret != 3) {
*/
if (capture) {
snprintf(info[i].ctrl_name, CONTROL_NAMELEN_MAX, "%s", ctrl_name);
- snprintf(info[i].cgrp_path, FILENAME_MAX, "%s", cgroup_name);
+ snprintf(info[i].cgrp_path, FILENAME_MAX, "%s", cgrp_name);
}
if (!is_cgroup_mode_unified()) {
continue;
/* skip if the cgroup path doesn't have systemd scope format */
- if (strstr(cgroup_name, ".scope") == NULL ||
- strstr(cgroup_name, ".slice") == NULL)
+ if (strstr(cgrp_name, ".scope") == NULL ||
+ strstr(cgrp_name, ".slice") == NULL)
continue;
/* skip if we have already searched cgroup for idle_thread */
- if (is_scope_parsed(cgroup_name))
+ if (is_scope_parsed(cgrp_name))
continue;
if (ret == 2)
- ret = cgroup_get_procs(cgroup_name, NULL, &pids, &size);
+ ret = cgroup_get_procs(cgrp_name, NULL, &pids, &size);
else
- ret = cgroup_get_procs(cgroup_name, ctrl_name, &pids, &size);
+ ret = cgroup_get_procs(cgrp_name, ctrl_name, &pids, &size);
if (ret) {
- err("Failed to read cgroup.procs of cgroup: %s\n", cgroup_name + 1);
+ err("Failed to read cgroup.procs of cgroup: %s\n", cgrp_name + 1);
scope_pid = -1;
goto out;
}
* ../systemd/<slice>/<scope>/cgroup.procs (legacy/hybrid)
* ../unified/<slice>/<scope>/cgroup.procs (hybrid)
*/
- snprintf(scope_name, FILENAME_MAX, "%s", cgroup_name);
+ snprintf(scope_name, FILENAME_MAX, "%s", cgrp_name);
scope_pid = _scope_pid;
continue;
}
static void find_mnt_point(const char * const controller, char **mnt_point)
{
char proc_mount[] = "/proc/mounts";
- char cgroup_path[FILENAME_MAX];
+ char cgrp_path[FILENAME_MAX];
char buffer[FILENAME_MAX * 2];
FILE *proc_mount_f = NULL;
int ret;
continue;
if (strcmp(controller, "name=systemd") == 0) {
- if (!strstr(buffer, "name=systemd ") &&
- !strstr(buffer, "name=systemd,"))
+ if (!strstr(buffer, "name=systemd ") && !strstr(buffer, "name=systemd,"))
continue;
}
- ret = sscanf(buffer, "%*s %4096s\n", cgroup_path);
+ ret = sscanf(buffer, "%*s %4096s\n", cgrp_path);
if (ret != 1) {
err("Failed during read of %s:%s\n", proc_mount, strerror(errno));
goto out;
}
- *mnt_point = strdup(cgroup_path);
+ *mnt_point = strdup(cgrp_path);
if (!*mnt_point)
- err("strdup of %s failed\n", cgroup_path);
+ err("strdup of %s failed\n", cgrp_path);
break;
}
static int write_systemd_unified(const char * const scope_name, pid_t pid)
{
- char cgroup_procs_path[FILENAME_MAX + 14];
- FILE *cgroup_systemd_path_f = NULL;
- FILE *cgroup_unified_path_f = NULL;
- char *cgroup_name = NULL;
+ char cgrp_procs_path[FILENAME_MAX + 14];
+ FILE *cgrp_systemd_path_f = NULL;
+ FILE *cgrp_unified_path_f = NULL;
+ char *cgrp_name = NULL;
/* construct the systemd cgroup path, by parsing /proc/mounts */
- find_mnt_point("name=systemd", &cgroup_name);
- if (!cgroup_name) {
+ find_mnt_point("name=systemd", &cgrp_name);
+ if (!cgrp_name) {
err("Unable find name=systemd cgroup path\n");
return -1;
}
- snprintf(cgroup_procs_path, sizeof(cgroup_procs_path), "%s/%s/cgroup.procs",
- cgroup_name, scope_name);
- free(cgroup_name);
+ snprintf(cgrp_procs_path, sizeof(cgrp_procs_path), "%s/%s/cgroup.procs",
+ cgrp_name, scope_name);
+ free(cgrp_name);
- cgroup_systemd_path_f = fopen(cgroup_procs_path, "we");
- if (!cgroup_systemd_path_f) {
- err("Failed to open %s\n", cgroup_procs_path);
+ cgrp_systemd_path_f = fopen(cgrp_procs_path, "we");
+ if (!cgrp_systemd_path_f) {
+ err("Failed to open %s\n", cgrp_procs_path);
return -1;
}
* construct the unified cgroup path, by parsing
* /proc/mounts
*/
- find_mnt_point("unified", &cgroup_name);
- if (!cgroup_name) {
+ find_mnt_point("unified", &cgrp_name);
+ if (!cgrp_name) {
err("Unable find unified cgroup path\n");
- fclose(cgroup_systemd_path_f);
+ fclose(cgrp_systemd_path_f);
return -1;
}
- snprintf(cgroup_procs_path, sizeof(cgroup_procs_path), "%s/%s/cgroup.procs",
- cgroup_name, scope_name);
- free(cgroup_name);
+ snprintf(cgrp_procs_path, sizeof(cgrp_procs_path), "%s/%s/cgroup.procs",
+ cgrp_name, scope_name);
+ free(cgrp_name);
- cgroup_unified_path_f = fopen(cgroup_procs_path, "we");
- if (!cgroup_unified_path_f) {
- err("Failed to open %s\n", cgroup_procs_path);
- fclose(cgroup_systemd_path_f);
+ cgrp_unified_path_f = fopen(cgrp_procs_path, "we");
+ if (!cgrp_unified_path_f) {
+ err("Failed to open %s\n", cgrp_procs_path);
+ fclose(cgrp_systemd_path_f);
return -1;
}
}
- fprintf(cgroup_systemd_path_f, "%d", pid);
- fflush(cgroup_systemd_path_f);
- fclose(cgroup_systemd_path_f);
+ fprintf(cgrp_systemd_path_f, "%d", pid);
+ fflush(cgrp_systemd_path_f);
+ fclose(cgrp_systemd_path_f);
if (!is_cgroup_mode_hybrid())
return 0;
- fprintf(cgroup_unified_path_f, "%d", pid);
- fflush(cgroup_unified_path_f);
- fclose(cgroup_unified_path_f);
+ fprintf(cgrp_unified_path_f, "%d", pid);
+ fflush(cgrp_unified_path_f);
+ fclose(cgrp_unified_path_f);
return 0;
}
static int rollback_pid_cgroups(pid_t pid)
{
- char cgroup_proc_path[FILENAME_MAX + 14];
- char cgroup_path[FILENAME_MAX];
- int err = 0, idx = 0, ret = 0;
- char *cgrp_proc_path = NULL;
+ char cgrp_proc_path[FILENAME_MAX + 14];
+ char cgrp_path[FILENAME_MAX];
+ char *_cgrp_proc_path = NULL;
+ int err = 0, idx = 0;
+ int ret = 0;
/*
* unified cgroup rollback is simple, we need to write into
*/
if (is_cgroup_mode_unified()) {
pthread_rwlock_rdlock(&cg_mount_table_lock);
- cg_build_path_locked(info[idx].cgrp_path, cgroup_path, NULL);
+ cg_build_path_locked(info[idx].cgrp_path, cgrp_path, NULL);
pthread_rwlock_unlock(&cg_mount_table_lock);
- snprintf(cgroup_proc_path, FILENAME_MAX + 14, "%s/cgroup.procs", cgroup_path);
- ret = attach_task_pid(cgroup_proc_path, pid);
+ snprintf(cgrp_proc_path, FILENAME_MAX + 14, "%s/cgroup.procs", cgrp_path);
+ ret = attach_task_pid(cgrp_proc_path, pid);
return ret;
}
for (idx = 0; info[idx].ctrl_name[0] != '\0'; idx++) {
/* find the systemd cgroup path */
if (!strcmp(info[idx].ctrl_name, "name=systemd")) {
- find_mnt_point("name=systemd", &cgrp_proc_path);
- if (!cgrp_proc_path) {
+ find_mnt_point("name=systemd", &_cgrp_proc_path);
+ if (!_cgrp_proc_path) {
err("Unable find name=systemd cgroup path\n");
return -1;
}
- snprintf(cgroup_proc_path, FILENAME_MAX + 14, "%s/%s/cgroup.procs",
- cgrp_proc_path, info[idx].cgrp_path);
- free(cgrp_proc_path);
+ snprintf(cgrp_proc_path, FILENAME_MAX + 14, "%s/%s/cgroup.procs",
+ _cgrp_proc_path, info[idx].cgrp_path);
+ free(_cgrp_proc_path);
/* find the unified cgroup path */
} else if (is_cgroup_mode_hybrid() &&
!strcmp(info[idx].ctrl_name, "unified")) {
- find_mnt_point("unified cgroup2", &cgrp_proc_path);
- if (!cgrp_proc_path) {
+ find_mnt_point("unified cgroup2", &_cgrp_proc_path);
+ if (!_cgrp_proc_path) {
err("Unable find unified cgroup path\n");
return -1;
}
- snprintf(cgroup_proc_path, FILENAME_MAX + 14, "%s/%s/cgroup.procs",
- cgrp_proc_path, info[idx].cgrp_path);
- free(cgrp_proc_path);
+ snprintf(cgrp_proc_path, FILENAME_MAX + 14, "%s/%s/cgroup.procs",
+ _cgrp_proc_path, info[idx].cgrp_path);
+ free(_cgrp_proc_path);
/* find other controller hierarchy path */
} else {
pthread_rwlock_rdlock(&cg_mount_table_lock);
- cg_build_path_locked(info[idx].cgrp_path, cgroup_path, info[idx].ctrl_name);
+ cg_build_path_locked(info[idx].cgrp_path, cgrp_path, info[idx].ctrl_name);
pthread_rwlock_unlock(&cg_mount_table_lock);
- snprintf(cgroup_proc_path, FILENAME_MAX + 14, "%s/cgroup.procs",
- cgroup_path);
+ snprintf(cgrp_proc_path, FILENAME_MAX + 14, "%s/cgroup.procs", cgrp_path);
}
/* record the error and continue */
- ret = attach_task_pid(cgroup_proc_path, pid);
+ ret = attach_task_pid(cgrp_proc_path, pid);
if (ret)
err = -1;
}
mode_t file_mode = NO_PERMS;
mode_t dir_mode = NO_PERMS;
- struct cgroup *default_group = NULL;
+ struct cgroup *default_cgrp = NULL;
int filem_change = 0;
int dirm_change = 0;
int ret, error = 0;
}
/* set default permissions */
- default_group = cgroup_new_cgroup("default");
- if (!default_group) {
+ default_cgrp = cgroup_new_cgroup("default");
+ if (!default_cgrp) {
error = -1;
err("%s: cannot create default cgroup\n", argv[0]);
goto err;
}
- error = cgroup_set_uid_gid(default_group, tuid, tgid, auid, agid);
+ error = cgroup_set_uid_gid(default_cgrp, tuid, tgid, auid, agid);
if (error) {
err("%s: cannot set default UID and GID: %s\n", argv[0], cgroup_strerror(error));
goto free_cgroup;
}
if (dirm_change | filem_change)
- cgroup_set_permissions(default_group, dir_mode, file_mode, tasks_mode);
+ cgroup_set_permissions(default_cgrp, dir_mode, file_mode, tasks_mode);
- error = cgroup_config_set_default(default_group);
+ error = cgroup_config_set_default(default_cgrp);
if (error) {
err("%s: cannot set config parser defaults: %s\n", argv[0],
cgroup_strerror(error));
}
free_cgroup:
- cgroup_free(&default_group);
+ cgroup_free(&default_cgrp);
err:
cgroup_string_list_free(&cfg_files);
}
#ifdef WITH_SYSTEMD
-static int create_systemd_scope(struct cgroup * const cg, const char * const prog_name,
+static int create_systemd_scope(struct cgroup * const cgrp, const char * const prog_name,
int set_default, pid_t pid)
{
struct cgroup_systemd_scope_opts opts;
opts.pid = pid;
- ret = cgroup_create_scope2(cg, 0, &opts);
+ ret = cgroup_create_scope2(cgrp, 0, &opts);
if (!ret && set_default) {
- scope = strstr(cg->name, "/");
+ scope = strstr(cgrp->name, "/");
if (!scope) {
err("%s: Invalid scope name %s, expected <slice>/<scope>\n",
- prog_name, cg->name);
+ prog_name, cgrp->name);
ret = ECGINVAL;
goto err;
}
- len = strlen(cg->name) - strlen(scope);
- strncpy(slice, cg->name, FILENAME_MAX - 1);
+ len = strlen(cgrp->name) - strlen(scope);
+ strncpy(slice, cgrp->name, FILENAME_MAX - 1);
slice[len] = '\0';
scope++;
* cgroup_write_systemd_default_cgroup() returns 0 on failure
*/
if (ret == 0) {
- err("%s: failed to write default %s/%s to ",
+ err("%s: failed to write default %s/%s to /var/run/libcgroup/systemd\n",
prog_name, slice, scope);
- err("/var/run/libcgroup/systemd\n");
ret = ECGINVAL;
goto err;
}
return ret;
}
#else
-static int create_systemd_scope(struct cgroup * const cg, const char * const prog_name,
+static int create_systemd_scope(struct cgroup * const cgrp, const char * const prog_name,
int set_default, pid_t pid)
{
return ECGINVAL;
int create_scope = 0;
pid_t scope_pid = -1;
- struct cgroup_group_spec **cgroup_list;
+ struct cgroup_group_spec **cgrp_list;
struct cgroup_controller *cgc;
- struct cgroup *cgroup;
+ struct cgroup *cgrp;
/* approximation of max. numbers of groups that will be created */
int capacity = argc;
exit(EXIT_BADARGS);
}
- cgroup_list = calloc(capacity, sizeof(struct cgroup_group_spec *));
- if (cgroup_list == NULL) {
+ cgrp_list = calloc(capacity, sizeof(struct cgroup_group_spec *));
+ if (cgrp_list == NULL) {
err("%s: out of memory\n", argv[0]);
ret = -1;
goto err;
goto err;
break;
case 'g':
- ret = parse_cgroup_spec(cgroup_list, optarg, capacity);
+ ret = parse_cgroup_spec(cgrp_list, optarg, capacity);
if (ret) {
err("%s: cgroup controller and path parsing failed (%s)\n",
argv[0], argv[optind]);
/* for each new cgroup */
for (i = 0; i < capacity; i++) {
- if (!cgroup_list[i])
+ if (!cgrp_list[i])
break;
/* create the new cgroup structure */
- cgroup = cgroup_new_cgroup(cgroup_list[i]->path);
- if (!cgroup) {
+ cgrp = cgroup_new_cgroup(cgrp_list[i]->path);
+ if (!cgrp) {
ret = ECGFAIL;
err("%s: can't add new cgroup: %s\n", argv[0], cgroup_strerror(ret));
goto err;
}
/* set uid and gid for the new cgroup based on input options */
- ret = cgroup_set_uid_gid(cgroup, tuid, tgid, auid, agid);
+ ret = cgroup_set_uid_gid(cgrp, tuid, tgid, auid, agid);
if (ret)
goto err;
/* add controllers to the new cgroup */
j = 0;
- while (cgroup_list[i]->controllers[j]) {
- if (strcmp(cgroup_list[i]->controllers[j], "*") == 0) {
+ while (cgrp_list[i]->controllers[j]) {
+ if (strcmp(cgrp_list[i]->controllers[j], "*") == 0) {
/* it is meta character, add all controllers */
- ret = cgroup_add_all_controllers(cgroup);
+ ret = cgroup_add_all_controllers(cgrp);
if (ret != 0) {
ret = ECGINVAL;
err("%s: can't add all controllers\n", argv[0]);
- cgroup_free(&cgroup);
+ cgroup_free(&cgrp);
goto err;
}
} else {
- cgc = cgroup_add_controller(cgroup,
- cgroup_list[i]->controllers[j]);
+ cgc = cgroup_add_controller(cgrp,
+ cgrp_list[i]->controllers[j]);
if (!cgc) {
ret = ECGINVAL;
err("%s: controller %s can't be add\n", argv[0],
- cgroup_list[i]->controllers[j]);
- cgroup_free(&cgroup);
+ cgrp_list[i]->controllers[j]);
+ cgroup_free(&cgrp);
goto err;
}
}
/* all variables set so create cgroup */
if (dirm_change | filem_change)
- cgroup_set_permissions(cgroup, dir_mode, file_mode, tasks_mode);
+ cgroup_set_permissions(cgrp, dir_mode, file_mode, tasks_mode);
if (create_scope)
- ret = create_systemd_scope(cgroup, argv[0], set_default_scope, scope_pid);
+ ret = create_systemd_scope(cgrp, argv[0], set_default_scope, scope_pid);
else
- ret = cgroup_create_cgroup(cgroup, 0);
+ ret = cgroup_create_cgroup(cgrp, 0);
if (ret) {
- err("%s: can't create cgroup %s: %s\n", argv[0], cgroup->name,
+ err("%s: can't create cgroup %s: %s\n", argv[0], cgrp->name,
cgroup_strerror(ret));
- cgroup_free(&cgroup);
+ cgroup_free(&cgrp);
goto err;
}
- cgroup_free(&cgroup);
+ cgroup_free(&cgrp);
}
err:
- if (cgroup_list) {
+ if (cgrp_list) {
for (i = 0; i < capacity; i++) {
- if (cgroup_list[i])
- cgroup_free_group_spec(cgroup_list[i]);
+ if (cgrp_list[i])
+ cgroup_free_group_spec(cgrp_list[i]);
}
- free(cgroup_list);
+ free(cgrp_list);
}
return ret;
#ifdef WITH_SYSTEMD
int ignore_default_systemd_delegate_slice = 0;
#endif
- struct cgroup_group_spec **cgroup_list = NULL;
+ struct cgroup_group_spec **cgrp_list = NULL;
struct ext_cgroup_record *ecg_list = NULL;
struct cgroup_controller *cgc;
- struct cgroup *cgroup;
+ struct cgroup *cgrp;
int final_ret = 0;
int counter = 0;
goto err;
}
- cgroup_list = calloc(argc, sizeof(struct cgroup_group_spec *));
- if (cgroup_list == NULL) {
+ cgrp_list = calloc(argc, sizeof(struct cgroup_group_spec *));
+ if (cgrp_list == NULL) {
err("%s: out of memory\n", argv[0]);
ret = -1;
goto err;
flags |= CGFLAG_DELETE_RECURSIVE;
break;
case 'g':
- ret = parse_cgroup_spec(cgroup_list, optarg, argc);
+ ret = parse_cgroup_spec(cgrp_list, optarg, argc);
if (ret != 0) {
err("%s: error parsing cgroup '%s'", argv[0], optarg);
ret = EXIT_BADARGS;
/* parse groups on command line */
for (i = optind; i < argc; i++) {
- ret = parse_cgroup_spec(cgroup_list, argv[i], argc);
+ ret = parse_cgroup_spec(cgrp_list, argv[i], argc);
if (ret != 0) {
err("%s: error parsing cgroup '%s'\n", argv[0], argv[i]);
ret = EXIT_BADARGS;
/* for each cgroup to be deleted */
for (i = 0; i < argc; i++) {
- if (!cgroup_list[i])
+ if (!cgrp_list[i])
break;
/* create the new cgroup structure */
- cgroup = cgroup_new_cgroup(cgroup_list[i]->path);
- if (!cgroup) {
+ cgrp = cgroup_new_cgroup(cgrp_list[i]->path);
+ if (!cgrp) {
ret = ECGFAIL;
err("%s: can't create new cgroup: %s\n", argv[0], cgroup_strerror(ret));
goto err;
/* add controllers to the cgroup */
j = 0;
- while (cgroup_list[i]->controllers[j]) {
+ while (cgrp_list[i]->controllers[j]) {
skip = 0;
/*
* save controller name, cg name and hierarchy
}
strncpy(ecg_list[counter].controller,
- cgroup_list[i]->controllers[j], FILENAME_MAX);
+ cgrp_list[i]->controllers[j], FILENAME_MAX);
ecg_list[counter].controller[FILENAME_MAX - 1] = '\0';
- strncpy(ecg_list[counter].name,
- cgroup_list[i]->path, FILENAME_MAX);
+ strncpy(ecg_list[counter].name, cgrp_list[i]->path, FILENAME_MAX);
ecg_list[counter].name[FILENAME_MAX - 1] = '\0';
ret = skip_add_controller(counter, &skip, ecg_list);
goto next;
}
- cgc = cgroup_add_controller(cgroup, cgroup_list[i]->controllers[j]);
+ cgc = cgroup_add_controller(cgrp, cgrp_list[i]->controllers[j]);
if (!cgc) {
ret = ECGFAIL;
err("%s: controller %s can't be added\n", argv[0],
- cgroup_list[i]->controllers[j]);
- cgroup_free(&cgroup);
+ cgrp_list[i]->controllers[j]);
+ cgroup_free(&cgrp);
goto err;
}
next:
j++;
}
- ret = cgroup_delete_cgroup_ext(cgroup, flags);
+ ret = cgroup_delete_cgroup_ext(cgrp, flags);
/* Remember the errors and continue, try to remove all groups. */
if (ret != 0) {
- err("%s: cannot remove group '%s': %s\n", argv[0], cgroup->name,
+ err("%s: cannot remove group '%s': %s\n", argv[0], cgrp->name,
cgroup_strerror(ret));
final_ret = ret;
}
- cgroup_free(&cgroup);
+ cgroup_free(&cgrp);
}
ret = final_ret;
if (ecg_list)
free(ecg_list);
- if (cgroup_list) {
+ if (cgrp_list) {
for (i = 0; i < argc; i++) {
- if (cgroup_list[i])
- cgroup_free_group_spec(cgroup_list[i]);
+ if (cgrp_list[i])
+ cgroup_free_group_spec(cgrp_list[i]);
}
- free(cgroup_list);
+ free(cgrp_list);
}
return ret;
int main(int argc, char *argv[])
{
- struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
+ struct cgroup_group_spec *cgrp_list[CG_HIER_MAX];
#ifdef WITH_SYSTEMD
int ignore_default_systemd_delegate_slice = 0;
#endif
pid_t pid;
int c;
- memset(cgroup_list, 0, sizeof(cgroup_list));
+ memset(cgrp_list, 0, sizeof(cgrp_list));
#ifdef WITH_SYSTEMD
while ((c = getopt_long(argc, argv, "+g:shbr", longopts, NULL)) > 0) {
switch (c) {
switch (c) {
#endif
case 'g':
- ret = parse_cgroup_spec(cgroup_list, optarg, CG_HIER_MAX);
+ ret = parse_cgroup_spec(cgrp_list, optarg, CG_HIER_MAX);
if (ret) {
err("cgroup controller and path parsing failed\n");
exit(EXIT_BADARGS);
* and controllers
*/
for (i = 0; i < CG_HIER_MAX; i++) {
- if (!cgroup_list[i])
+ if (!cgrp_list[i])
break;
- ret = cgroup_change_cgroup_path(cgroup_list[i]->path, pid,
- (const char *const*) cgroup_list[i]->controllers);
+ ret = cgroup_change_cgroup_path(cgrp_list[i]->path, pid,
+ (const char *const*) cgrp_list[i]->controllers);
if (ret) {
err("cgroup change of group failed\n");
return ret;
{
pid_t _scope_pid = -1, scope_pid = -1;
char ctrl_name[CONTROL_NAMELEN_MAX];
- char cgroup_name[FILENAME_MAX];
char scope_name[FILENAME_MAX];
+ char cgrp_name[FILENAME_MAX];
int found_systemd_cgrp = 0;
int found_unified_cgrp = 0;
char buffer[FILENAME_MAX];
/* read according to the cgroup mode */
if (strstr(buffer, "::"))
- ret = sscanf(buffer, "%d::%4096s\n", &idx, cgroup_name);
+ ret = sscanf(buffer, "%d::%4096s\n", &idx, cgrp_name);
else
- ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgroup_name);
+ ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgrp_name);
if (ret != 2 && ret != 3) {
err("Unrecognized cgroup file format: %s\n", buffer);
}
/* skip if the cgroup path doesn't have systemd scope format */
- if (strstr(cgroup_name, ".scope") == NULL ||
- strstr(cgroup_name, ".slice") == NULL)
+ if (strstr(cgrp_name, ".scope") == NULL ||
+ strstr(cgrp_name, ".slice") == NULL)
continue;
/* skip if we have already searched cgroup for idle_thread */
- if (is_scope_parsed(cgroup_name))
+ if (is_scope_parsed(cgrp_name))
continue;
/* cgroup v1 might have shared mount points cpu,cpuacct */
}
if (ret == 2)
- ret = cgroup_get_procs(cgroup_name, NULL, &pids, &size);
+ ret = cgroup_get_procs(cgrp_name, NULL, &pids, &size);
else
- ret = cgroup_get_procs(cgroup_name, ctrl_name, &pids, &size);
+ ret = cgroup_get_procs(cgrp_name, ctrl_name, &pids, &size);
if (ret) {
- err("Failed to read cgroup.procs of cgroup: %s\n", cgroup_name + 1);
+ err("Failed to read cgroup.procs of cgroup: %s\n", cgrp_name + 1);
goto out;
}
* ../systemd/<slice>/<scope>/cgroup.procs (legacy/hybrid)
* ../unified/<slice>/<scope>/cgroup.procs (hybrid)
*/
- snprintf(scope_name, FILENAME_MAX, "%s", cgroup_name);
+ snprintf(scope_name, FILENAME_MAX, "%s", cgrp_name);
scope_pid = _scope_pid;
continue;
}
static void find_mnt_point(const char * const controller, char **mnt_point)
{
char proc_mount[] = "/proc/mounts";
- char cgroup_path[FILENAME_MAX];
char buffer[FILENAME_MAX * 2];
+ char cgrp_path[FILENAME_MAX];
FILE *proc_mount_f = NULL;
int ret;
if (!strstr(buffer, controller))
continue;
- ret = sscanf(buffer, "%*s %4096s\n", cgroup_path);
+ ret = sscanf(buffer, "%*s %4096s\n", cgrp_path);
if (ret != 1) {
err("Failed during read of %s:%s\n", proc_mount, strerror(errno));
goto out;
}
- *mnt_point = strdup(cgroup_path);
+ *mnt_point = strdup(cgrp_path);
if (!*mnt_point)
- err("strdup of %s failed\n", cgroup_path);
+ err("strdup of %s failed\n", cgrp_path);
break;
}
static int write_systemd_unified(const char * const scope_name)
{
- char cgroup_procs_path[FILENAME_MAX * 2 + 25];
- FILE *cgroup_systemd_path_f = NULL;
- FILE *cgroup_unified_path_f = NULL;
- char *cgroup_name = NULL;
+ char cgrp_procs_path[FILENAME_MAX * 2 + 25];
+ FILE *cgrp_systemd_path_f = NULL;
+ FILE *cgrp_unified_path_f = NULL;
+ char *cgrp_name = NULL;
pid_t pid;
/* construct the systemd cgroup path, by parsing /proc/mounts */
- find_mnt_point("name=systemd ", &cgroup_name);
- if (!cgroup_name) {
+ find_mnt_point("name=systemd ", &cgrp_name);
+ if (!cgrp_name) {
err("Unable find name=systemd cgroup path\n");
return -1;
}
- snprintf(cgroup_procs_path, sizeof(cgroup_procs_path), "%s/%s/cgroup.procs",
- cgroup_name, scope_name);
- free(cgroup_name);
+ snprintf(cgrp_procs_path, sizeof(cgrp_procs_path), "%s/%s/cgroup.procs",
+ cgrp_name, scope_name);
+ free(cgrp_name);
- cgroup_systemd_path_f = fopen(cgroup_procs_path, "we");
- if (!cgroup_systemd_path_f) {
- err("Failed to open %s\n", cgroup_procs_path);
+ cgrp_systemd_path_f = fopen(cgrp_procs_path, "we");
+ if (!cgrp_systemd_path_f) {
+ err("Failed to open %s\n", cgrp_procs_path);
return -1;
}
* construct the unified cgroup path, by parsing
* /proc/mounts
*/
- find_mnt_point("unified cgroup2", &cgroup_name);
- if (!cgroup_name) {
+ find_mnt_point("unified cgroup2", &cgrp_name);
+ if (!cgrp_name) {
err("Unable find unified cgroup path\n");
- fclose(cgroup_systemd_path_f);
+ fclose(cgrp_systemd_path_f);
return -1;
}
- snprintf(cgroup_procs_path, sizeof(cgroup_procs_path), "%s/%s/cgroup.procs",
- cgroup_name, scope_name);
- free(cgroup_name);
+ snprintf(cgrp_procs_path, sizeof(cgrp_procs_path), "%s/%s/cgroup.procs",
+ cgrp_name, scope_name);
+ free(cgrp_name);
- cgroup_unified_path_f = fopen(cgroup_procs_path, "we");
- if (!cgroup_unified_path_f) {
- err("Failed to open %s\n", cgroup_procs_path);
- fclose(cgroup_systemd_path_f);
+ cgrp_unified_path_f = fopen(cgrp_procs_path, "we");
+ if (!cgrp_unified_path_f) {
+ err("Failed to open %s\n", cgrp_procs_path);
+ fclose(cgrp_systemd_path_f);
return -1;
}
}
pid = getpid();
- fprintf(cgroup_systemd_path_f, "%d", pid);
- fflush(cgroup_systemd_path_f);
- fclose(cgroup_systemd_path_f);
+ fprintf(cgrp_systemd_path_f, "%d", pid);
+ fflush(cgrp_systemd_path_f);
+ fclose(cgrp_systemd_path_f);
if (!is_cgroup_mode_hybrid())
return 0;
- fprintf(cgroup_unified_path_f, "%d", pid);
- fflush(cgroup_unified_path_f);
- fclose(cgroup_unified_path_f);
+ fprintf(cgrp_unified_path_f, "%d", pid);
+ fflush(cgrp_unified_path_f);
+ fclose(cgrp_unified_path_f);
return 0;
}
return 0;
}
-static int create_cg(struct cgroup **cg_list[], int * const cg_list_len)
+static int create_cgrp(struct cgroup **cgrp_list[], int * const cgrp_list_len)
{
- *cg_list = realloc(*cg_list, ((*cg_list_len) + 1) * sizeof(struct cgroup *));
- if ((*cg_list) == NULL)
+ *cgrp_list = realloc(*cgrp_list, ((*cgrp_list_len) + 1) * sizeof(struct cgroup *));
+ if ((*cgrp_list) == NULL)
return ECGCONTROLLERCREATEFAILED;
- memset(&(*cg_list)[*cg_list_len], 0, sizeof(struct cgroup *));
+ memset(&(*cgrp_list)[*cgrp_list_len], 0, sizeof(struct cgroup *));
- (*cg_list)[*cg_list_len] = cgroup_new_cgroup("");
- if ((*cg_list)[*cg_list_len] == NULL)
+ (*cgrp_list)[*cgrp_list_len] = cgroup_new_cgroup("");
+ if ((*cgrp_list)[*cgrp_list_len] == NULL)
return ECGCONTROLLERCREATEFAILED;
- (*cg_list_len)++;
+ (*cgrp_list_len)++;
return 0;
}
-static int parse_a_flag(struct cgroup **cg_list[], int * const cg_list_len)
+static int parse_a_flag(struct cgroup **cgrp_list[], int * const cgrp_list_len)
{
struct cgroup_mount_point controller;
struct cgroup_controller *cgc;
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
void *handle;
int ret = 0;
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cgrp(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* an optarg at the end with no flag. Let's temporarily populate
* the first cgroup with the requested control values.
*/
- cg = (*cg_list)[0];
+ cgrp = (*cgrp_list)[0];
ret = cgroup_get_controller_begin(&handle, &controller);
while (ret == 0) {
- cgc = cgroup_get_controller(cg, controller.name);
+ cgc = cgroup_get_controller(cgrp, controller.name);
if (!cgc) {
- cgc = cgroup_add_controller(cg, controller.name);
+ cgc = cgroup_add_controller(cgrp, controller.name);
if (!cgc) {
err("cgget: cannot find controller '%s'\n", controller.name);
ret = ECGOTHER;
return ret;
}
-static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_r_flag(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const cntl_value)
{
char *cntl_value_controller = NULL;
struct cgroup_controller *cgc;
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
int ret = 0;
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cgrp(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* an optarg at the end with no flag. Let's temporarily populate
* the first cgroup with the requested control values.
*/
- cg = (*cg_list)[0];
+ cgrp = (*cgrp_list)[0];
ret = get_controller_from_name(cntl_value, &cntl_value_controller);
if (ret)
goto out;
- cgc = cgroup_get_controller(cg, cntl_value_controller);
+ cgc = cgroup_get_controller(cgrp, cntl_value_controller);
if (!cgc) {
- cgc = cgroup_add_controller(cg, cntl_value_controller);
+ cgc = cgroup_add_controller(cgrp, cntl_value_controller);
if (!cgc) {
err("cgget: cannot find controller '%s'\n", cntl_value_controller);
ret = ECGOTHER;
return ret;
}
-static int parse_g_flag_no_colon(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_g_flag_no_colon(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
int ret = 0;
- if ((*cg_list_len) > 1) {
+ if ((*cgrp_list_len) > 1) {
ret = ECGMAXVALUESEXCEEDED;
goto out;
}
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cgrp(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* will be an optarg at the end with no flag. Let's temporarily
* populate the first cgroup with the requested control values.
*/
- cg = *cg_list[0];
+ cgrp = *cgrp_list[0];
- cgc = cgroup_get_controller(cg, ctrl_str);
+ cgc = cgroup_get_controller(cgrp, ctrl_str);
if (!cgc) {
- cgc = cgroup_add_controller(cg, ctrl_str);
+ cgc = cgroup_add_controller(cgrp, ctrl_str);
if (!cgc) {
err("cgget: cannot find controller '%s'\n", ctrl_str);
ret = ECGOTHER;
return ret;
}
-static int split_cgroup_name(const char * const ctrl_str, char *cg_name)
+static int split_cgroup_name(const char * const ctrl_str, char *cgrp_name)
{
char *colon;
colon = strchr(ctrl_str, ':');
if (colon == NULL) {
/* ctrl_str doesn't contain a ":" */
- cg_name[0] = '\0';
+ cgrp_name[0] = '\0';
return ECGINVAL;
}
- strncpy(cg_name, &colon[1], FILENAME_MAX - 1);
+ strncpy(cgrp_name, &colon[1], FILENAME_MAX - 1);
return 0;
}
return ret;
}
-static int parse_g_flag_with_colon(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_g_flag_with_colon(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
char **controllers = NULL;
int controllers_len = 0;
int i, ret = 0;
- ret = create_cg(cg_list, cg_list_len);
+ ret = create_cgrp(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- cg = (*cg_list)[(*cg_list_len) - 1];
+ cgrp = (*cgrp_list)[(*cgrp_list_len) - 1];
- ret = split_cgroup_name(ctrl_str, cg->name);
+ ret = split_cgroup_name(ctrl_str, cgrp->name);
if (ret)
goto out;
goto out;
for (i = 0; i < controllers_len; i++) {
- cgc = cgroup_get_controller(cg, controllers[i]);
+ cgc = cgroup_get_controller(cgrp, controllers[i]);
if (!cgc) {
- cgc = cgroup_add_controller(cg, controllers[i]);
+ cgc = cgroup_add_controller(cgrp, controllers[i]);
if (!cgc) {
err("cgget: cannot find controller '%s'\n", controllers[i]);
ret = ECGOTHER;
return ret;
}
-static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
- int * const cg_list_len, bool first_cg_is_dummy)
+static int parse_opt_args(int argc, char *argv[], struct cgroup **cgrp_list[],
+ int * const cgrp_list_len, bool first_cgrp_is_dummy)
{
- struct cgroup *cg = NULL;
+ struct cgroup *cgrp = NULL;
int ret = 0;
/*
* The first cgroup was temporarily populated and requires the
* user to provide a cgroup name as an opt
*/
- if (argv[optind] == NULL && first_cg_is_dummy) {
+ if (argv[optind] == NULL && first_cgrp_is_dummy) {
usage(1, argv[0]);
exit(EXIT_BADARGS);
}
* Example of a command that will hit this code:
* $ cgget -g cpu:mycgroup mycgroup
*/
- if (argv[optind] != NULL && (*cg_list_len) > 0 &&
- strcmp((*cg_list)[0]->name, "") != 0) {
+ if (argv[optind] != NULL && (*cgrp_list_len) > 0 &&
+ strcmp((*cgrp_list)[0]->name, "") != 0) {
usage(1, argv[0]);
exit(EXIT_BADARGS);
}
while (argv[optind] != NULL) {
- if ((*cg_list_len) > 0)
- cg = (*cg_list)[(*cg_list_len) - 1];
+ if ((*cgrp_list_len) > 0)
+ cgrp = (*cgrp_list)[(*cgrp_list_len) - 1];
else
- cg = NULL;
+ cgrp = NULL;
- if ((*cg_list_len) == 0) {
+ if ((*cgrp_list_len) == 0) {
/*
* The user didn't provide a '-r' or '-g' flag.
* The parse_a_flag() function can be reused here
* because we both have the same use case - gather
* all the data about this particular cgroup.
*/
- ret = parse_a_flag(cg_list, cg_list_len);
+ ret = parse_a_flag(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
- sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
- } else if (cg != NULL && strlen(cg->name) == 0) {
+ strncpy((*cgrp_list)[(*cgrp_list_len) - 1]->name, argv[optind],
+ sizeof((*cgrp_list)[(*cgrp_list_len) - 1]->name) - 1);
+ } else if (cgrp != NULL && strlen(cgrp->name) == 0) {
/*
* this cgroup was created based upon control/value
* pairs or with a -g <controller> option. we'll
* populate it with the parameter provided by the user
*/
- strncpy(cg->name, argv[optind], sizeof(cg->name) - 1);
+ strncpy(cgrp->name, argv[optind], sizeof(cgrp->name) - 1);
} else {
- ret = create_cg(cg_list, cg_list_len);
+ ret = create_cgrp(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- ret = cgroup_copy_cgroup((*cg_list)[(*cg_list_len) - 1],
- (*cg_list)[(*cg_list_len) - 2]);
+ ret = cgroup_copy_cgroup((*cgrp_list)[(*cgrp_list_len) - 1],
+ (*cgrp_list)[(*cgrp_list_len) - 2]);
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
- sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
+ strncpy((*cgrp_list)[(*cgrp_list_len) - 1]->name, argv[optind],
+ sizeof((*cgrp_list)[(*cgrp_list_len) - 1]->name) - 1);
}
optind++;
}
return ret;
}
-static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * const cg_list_len,
- int * const mode)
+static int parse_opts(int argc, char *argv[], struct cgroup **cgrp_list[],
+ int * const cgrp_list_len, int * const mode)
{
bool do_not_fill_controller = false;
- bool first_cgroup_is_dummy = false;
- bool cgroup_mount_type = false;
+ bool first_cgrp_is_dummy = false;
+ bool cgrp_mount_type = false;
bool fill_controller = false;
bool print_ctrl_ver = false;
int ret = 0;
break;
case 'r':
do_not_fill_controller = true;
- first_cgroup_is_dummy = true;
- ret = parse_r_flag(cg_list, cg_list_len, optarg);
+ first_cgrp_is_dummy = true;
+ ret = parse_r_flag(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
break;
case 'g':
fill_controller = true;
if (strchr(optarg, ':') == NULL) {
- first_cgroup_is_dummy = true;
- ret = parse_g_flag_no_colon(cg_list, cg_list_len, optarg);
+ first_cgrp_is_dummy = true;
+ ret = parse_g_flag_no_colon(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
} else {
- ret = parse_g_flag_with_colon(cg_list, cg_list_len, optarg);
+ ret = parse_g_flag_with_colon(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
}
break;
case 'a':
fill_controller = true;
- ret = parse_a_flag(cg_list, cg_list_len);
+ ret = parse_a_flag(cgrp_list, cgrp_list_len);
if (ret)
goto err;
break;
case 'm':
- cgroup_mount_type = true;
+ cgrp_mount_type = true;
break;
case 'c':
print_ctrl_ver = true;
}
/* '-m' and '-c' should not used with other options */
- if ((cgroup_mount_type || print_ctrl_ver) &&
+ if ((cgrp_mount_type || print_ctrl_ver) &&
(fill_controller || do_not_fill_controller)) {
usage(1, argv[0]);
exit(EXIT_BADARGS);
}
- if (cgroup_mount_type) {
+ if (cgrp_mount_type) {
ret = find_cgroup_mount_type();
if (ret)
goto err;
goto err;
}
- ret = parse_opt_args(argc, argv, cg_list, cg_list_len, first_cgroup_is_dummy);
+ ret = parse_opt_args(argc, argv, cgrp_list, cgrp_list_len, first_cgrp_is_dummy);
if (ret)
goto err;
return ret;
}
-static int get_cv_value(struct control_value * const cv, const char * const cg_name,
+static int get_cv_value(struct control_value * const cv, const char * const cgrp_name,
const char * const controller_name)
{
bool is_multiline = false;
char tmp_line[LL_MAX];
int ret;
- ret = cgroup_read_value_begin(controller_name, cg_name, cv->name, &handle, tmp_line,
+ ret = cgroup_read_value_begin(controller_name, cgrp_name, cv->name, &handle, tmp_line,
LL_MAX);
if (ret == ECGEOF)
goto read_end;
tmp_ret = cgroup_test_subsys_mounted(controller_name);
if (tmp_ret == 0) {
err("cgget: cannot find controller '%s' in group '%s'\n",
- controller_name, cg_name);
+ controller_name, cgrp_name);
} else {
err("variable file read failed %s\n", cgroup_strerror(ret));
}
return 0;
}
-static int fill_empty_controller(struct cgroup * const cg, struct cgroup_controller * const cgc)
+static int fill_empty_controller(struct cgroup * const cgrp, struct cgroup_controller * const cgc)
{
char cgrp_ctrl_path[FILENAME_MAX] = { '\0' };
char mnt_path[FILENAME_MAX] = { '\0' };
* line:
* cgget -g cpu:/foo
*/
- if (cg->name[0] == '/' && cg->name[1] != '\0' &&
+ if (cgrp->name[0] == '/' && cgrp->name[1] != '\0' &&
strncmp(mnt_path + (mnt_path_len - 7), ".scope/", 7) == 0) {
snprintf(tmp, FILENAME_MAX, "%s", dirname(mnt_path));
strncpy(mnt_path, tmp, FILENAME_MAX - 1);
}
}
#endif
- strncat(mnt_path, cg->name, FILENAME_MAX - mnt_path_len - 1);
+ strncat(mnt_path, cgrp->name, FILENAME_MAX - mnt_path_len - 1);
mnt_path[sizeof(mnt_path) - 1] = '\0';
if (access(mnt_path, F_OK))
goto out;
- if (!cg_build_path_locked(cg->name, cgrp_ctrl_path, cg_mount_table[i].name))
+ if (!cg_build_path_locked(cgrp->name, cgrp_ctrl_path, cg_mount_table[i].name))
goto out;
dir = opendir(cgrp_ctrl_path);
if (ctrl_dir->d_type != DT_REG)
continue;
- ret = cgroup_fill_cgc(ctrl_dir, cg, cgc, i);
+ ret = cgroup_fill_cgc(ctrl_dir, cgrp, cgc, i);
if (ret == ECGFAIL)
goto out;
return ret;
}
-static int get_controller_values(struct cgroup * const cg, struct cgroup_controller * const cgc)
+static int get_controller_values(struct cgroup * const cgrp, struct cgroup_controller * const cgc)
{
int ret = 0;
int i;
for (i = 0; i < cgc->index; i++) {
- ret = get_cv_value(cgc->values[i], cg->name, cgc->name);
+ ret = get_cv_value(cgc->values[i], cgrp->name, cgc->name);
if (ret)
goto out;
}
if (cgc->index == 0) {
/* fill the entire controller since no values were provided */
- ret = fill_empty_controller(cg, cgc);
+ ret = fill_empty_controller(cgrp, cgc);
if (ret)
goto out;
}
return ret;
}
-static int get_cgroup_values(struct cgroup * const cg)
+static int get_cgroup_values(struct cgroup * const cgrp)
{
int ret = 0;
int i;
- for (i = 0; i < cg->index; i++) {
- ret = get_controller_values(cg, cg->controller[i]);
+ for (i = 0; i < cgrp->index; i++) {
+ ret = get_controller_values(cgrp, cgrp->controller[i]);
if (ret)
break;
}
return ret;
}
-static int get_values(struct cgroup *cg_list[], int cg_list_len)
+static int get_values(struct cgroup *cgrp_list[], int cgrp_list_len)
{
int ret = 0;
int i;
- for (i = 0; i < cg_list_len; i++) {
- ret = get_cgroup_values(cg_list[i]);
+ for (i = 0; i < cgrp_list_len; i++) {
+ ret = get_cgroup_values(cgrp_list[i]);
if (ret)
break;
}
int main(int argc, char *argv[])
{
int mode = MODE_SHOW_NAMES | MODE_SHOW_HEADERS;
- struct cgroup **cg_list = NULL;
- int cg_list_len = 0;
+ struct cgroup **cgrp_list = NULL;
+ int cgrp_list_len = 0;
int ret = 0, i;
/* No parameter on input? */
mode |= MODE_SYSTEMD_DELEGATE;
#endif
- ret = parse_opts(argc, argv, &cg_list, &cg_list_len, &mode);
+ ret = parse_opts(argc, argv, &cgrp_list, &cgrp_list_len, &mode);
if (ret)
goto err;
if (mode & MODE_SYSTEMD_DELEGATE)
cgroup_set_default_systemd_cgroup();
- ret = get_values(cg_list, cg_list_len);
+ ret = get_values(cgrp_list, cgrp_list_len);
if (ret)
goto err;
- print_cgroups(cg_list, cg_list_len, mode);
+ print_cgroups(cgrp_list, cgrp_list_len, mode);
err:
- for (i = 0; i < cg_list_len; i++)
- cgroup_free(&(cg_list[i]));
+ for (i = 0; i < cgrp_list_len; i++)
+ cgroup_free(&(cgrp_list[i]));
return ret;
}
/* cgroup.subtree_control -r name, value */
static struct control_value *cgrp_subtree_ctrl_val;
-static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX])
+static struct cgroup *copy_name_value_from_cgroup(char src_cgrp_path[FILENAME_MAX])
{
- struct cgroup *src_cgroup;
+ struct cgroup *src_cgrp;
int ret = 0;
/* create source cgroup */
- src_cgroup = cgroup_new_cgroup(src_cg_path);
- if (!src_cgroup) {
+ src_cgrp = cgroup_new_cgroup(src_cgrp_path);
+ if (!src_cgrp) {
err("can't create cgroup: %s\n", cgroup_strerror(ECGFAIL));
- goto scgroup_err;
+ goto scgrp_err;
}
/* copy the name-version values to the cgroup structure */
- ret = cgroup_get_cgroup(src_cgroup);
+ ret = cgroup_get_cgroup(src_cgrp);
if (ret != 0) {
- err("cgroup %s error: %s\n", src_cg_path, cgroup_strerror(ret));
- goto scgroup_err;
+ err("cgroup %s error: %s\n", src_cgrp_path, cgroup_strerror(ret));
+ goto scgrp_err;
}
- return src_cgroup;
+ return src_cgrp;
-scgroup_err:
- cgroup_free(&src_cgroup);
+scgrp_err:
+ cgroup_free(&src_cgrp);
return NULL;
}
int recursive = 0;
int nv_max = 0;
- char src_cg_path[FILENAME_MAX] = "\0";
+ char src_cgrp_path[FILENAME_MAX] = "\0";
struct cgroup *subtree_cgrp = NULL;
struct cgroup *src_cgroup = NULL;
goto err;
}
flags |= FL_COPY;
- strncpy(src_cg_path, optarg, FILENAME_MAX);
- src_cg_path[FILENAME_MAX-1] = '\0';
+ strncpy(src_cgrp_path, optarg, FILENAME_MAX);
+ src_cgrp_path[FILENAME_MAX-1] = '\0';
break;
case 'R':
recursive = 1;
/* copy the name-value from the given group */
if ((flags & FL_COPY) != 0) {
- src_cgroup = copy_name_value_from_cgroup(src_cg_path);
+ src_cgroup = copy_name_value_from_cgroup(src_cgrp_path);
if (src_cgroup == NULL)
goto err;
}
* controllers records
* tail
*/
-static int display_cgroup_data(struct cgroup *group,
+static int display_cgroup_data(struct cgroup *cgrp,
char controller[CG_CONTROLLER_MAX][FILENAME_MAX],
- const char *group_path, int root_path_len, int first,
+ const char *cgrp_path, int root_path_len, int first,
const char *program_name)
{
- struct cgroup_controller *group_controller = NULL;
+ struct cgroup_controller *cgrp_controller = NULL;
char var_path[FILENAME_MAX];
char *value = NULL;
char *output_name;
char *name;
/* print the group definition header */
- fprintf(output_f, "group %s {\n", group->name);
+ fprintf(output_f, "group %s {\n", cgrp->name);
/* for all wanted controllers display controllers tag */
while (controller[i][0] != '\0') {
/* display the permission tags */
- ret = display_permissions(group_path, group->name, controller[i]);
+ ret = display_permissions(cgrp_path, cgrp->name, controller[i]);
if (ret)
return ret;
- group_controller = cgroup_get_controller(group, controller[i]);
- if (group_controller == NULL) {
+ cgrp_controller = cgroup_get_controller(cgrp, controller[i]);
+ if (cgrp_controller == NULL) {
info("cannot find controller '%s' in group '%s'\n", controller[i],
- group->name);
+ cgrp->name);
i++;
ret = -1;
continue;
else
fprintf(output_f, "\t%s {\n", controller[i]);
i++;
- nr_var = cgroup_get_value_name_count(group_controller);
+ nr_var = cgroup_get_value_name_count(cgrp_controller);
for (j = 0; j < nr_var; j++) {
- name = cgroup_get_value_name(group_controller, j);
+ name = cgroup_get_value_name(cgrp_controller, j);
/*
* For the non-root groups cgconfigparser set
* permissions of variable files to 777. Thus it
* is necessary to test the permissions of variable
- * files in the root group to find out whether the
+ * files in the root cgroup to find out whether the
* variable is writable.
*/
if (root_path_len >= FILENAME_MAX)
root_path_len = FILENAME_MAX - 1;
- strncpy(var_path, group_path, root_path_len);
+ strncpy(var_path, cgrp_path, root_path_len);
var_path[root_path_len] = '\0';
strncat(var_path, "/", FILENAME_MAX - strlen(var_path) - 1);
fprintf(output_f, "\t\tdevices.deny=\"a *:* rwm\";\n");
}
- ret = cgroup_get_value_string(group_controller, name, &value);
+ ret = cgroup_get_value_string(cgrp_controller, name, &value);
/* variable can not be read */
if (ret != 0) {
static int display_controller_data(char controller[CG_CONTROLLER_MAX][FILENAME_MAX],
const char *program_name)
{
- char cgroup_name[FILENAME_MAX];
+ char cgrp_name[FILENAME_MAX];
struct cgroup_file_info info;
- struct cgroup *group = NULL;
+ struct cgroup *cgrp = NULL;
int prefix_len;
void *handle;
int first = 1;
/* some group starts here */
if (info.type == CGROUP_FILE_TYPE_DIR) {
/* parse the group name from full_path*/
- strncpy(cgroup_name, &info.full_path[prefix_len], FILENAME_MAX);
- cgroup_name[FILENAME_MAX-1] = '\0';
+ strncpy(cgrp_name, &info.full_path[prefix_len], FILENAME_MAX);
+ cgrp_name[FILENAME_MAX-1] = '\0';
/* start to grab data about the new group */
- group = cgroup_new_cgroup(cgroup_name);
- if (group == NULL) {
- info("cannot create group '%s'\n", cgroup_name);
+ cgrp = cgroup_new_cgroup(cgrp_name);
+ if (cgrp == NULL) {
+ info("cannot create cgrp '%s'\n", cgrp_name);
ret = ECGFAIL;
goto err;
}
- ret = cgroup_get_cgroup(group);
+ ret = cgroup_get_cgroup(cgrp);
if (ret != 0) {
/*
* We know for sure that the cgroup exists
* file.
*/
if (ret != ECGROUPNOTEXIST) {
- info("cannot read group '%s': %s %d\n", cgroup_name,
+ info("cannot read group '%s': %s %d\n", cgrp_name,
cgroup_strerror(ret), ret);
goto err;
}
}
if (ret == 0)
- display_cgroup_data(group, controller, info.full_path, prefix_len,
+ display_cgroup_data(cgrp, controller, info.full_path, prefix_len,
first, program_name);
first = 0;
- cgroup_free(&group);
+ cgroup_free(&cgrp);
}
}
return 0;
}
-static int create_cg(struct cgroup **cg_list[], int * const cg_list_len)
+static int create_cg(struct cgroup **cgrp_list[], int * const cgrp_list_len)
{
- *cg_list = realloc(*cg_list, ((*cg_list_len) + 1) * sizeof(struct cgroup *));
- if ((*cg_list) == NULL)
+ *cgrp_list = realloc(*cgrp_list, ((*cgrp_list_len) + 1) * sizeof(struct cgroup *));
+ if ((*cgrp_list) == NULL)
return ECGCONTROLLERCREATEFAILED;
- memset(&(*cg_list)[*cg_list_len], 0, sizeof(struct cgroup *));
+ memset(&(*cgrp_list)[*cgrp_list_len], 0, sizeof(struct cgroup *));
- (*cg_list)[*cg_list_len] = cgroup_new_cgroup("");
- if ((*cg_list)[*cg_list_len] == NULL)
+ (*cgrp_list)[*cgrp_list_len] = cgroup_new_cgroup("");
+ if ((*cgrp_list)[*cgrp_list_len] == NULL)
return ECGCONTROLLERCREATEFAILED;
- (*cg_list_len)++;
+ (*cgrp_list_len)++;
return 0;
}
-static int parse_a_flag(struct cgroup **cg_list[], int * const cg_list_len)
+static int parse_a_flag(struct cgroup **cgrp_list[], int * const cgrp_list_len)
{
struct cgroup_mount_point controller;
struct cgroup_controller *cgc;
void *handle;
int ret = 0;
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cg(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* an optarg at the end with no flag. Let's temporarily populate
* the first cgroup with the requested control values.
*/
- cg = (*cg_list)[0];
+ cg = (*cgrp_list)[0];
ret = cgroup_get_controller_begin(&handle, &controller);
while (ret == 0) {
return ret;
}
-static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_r_flag(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const cntl_value)
{
char *cntl_value_controller = NULL;
struct cgroup *cg = NULL;
int ret = 0;
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cg(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* an optarg at the end with no flag. Let's temporarily populate
* the first cgroup with the requested control values.
*/
- cg = (*cg_list)[0];
+ cg = (*cgrp_list)[0];
ret = get_controller_from_name(cntl_value, &cntl_value_controller);
if (ret)
return ret;
}
-static int parse_g_flag_no_colon(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_g_flag_no_colon(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
struct cgroup *cg = NULL;
int ret = 0;
- if ((*cg_list_len) > 1) {
+ if ((*cgrp_list_len) > 1) {
ret = ECGMAXVALUESEXCEEDED;
goto out;
}
- if ((*cg_list_len) == 0) {
- ret = create_cg(cg_list, cg_list_len);
+ if ((*cgrp_list_len) == 0) {
+ ret = create_cg(cgrp_list, cgrp_list_len);
if (ret)
goto out;
}
* Let's temporarily populate the first cgroup with the requested
* control values.
*/
- cg = *cg_list[0];
+ cg = *cgrp_list[0];
cgc = cgroup_get_controller(cg, ctrl_str);
if (!cgc) {
return ret;
}
-static int split_cgroup_name(const char * const ctrl_str, char *cg_name)
+static int split_cgroup_name(const char * const ctrl_str, char *cgrp_name)
{
char *colon;
colon = strchr(ctrl_str, ':');
if (colon == NULL) {
/* ctrl_str doesn't contain a ":" */
- cg_name[0] = '\0';
+ cgrp_name[0] = '\0';
return ECGINVAL;
}
- strncpy(cg_name, &colon[1], FILENAME_MAX - 1);
+ strncpy(cgrp_name, &colon[1], FILENAME_MAX - 1);
return 0;
}
return ret;
}
-static int parse_g_flag_with_colon(struct cgroup **cg_list[], int * const cg_list_len,
+static int parse_g_flag_with_colon(struct cgroup **cgrp_list[], int * const cgrp_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
int controllers_len = 0;
int i, ret = 0;
- ret = create_cg(cg_list, cg_list_len);
+ ret = create_cg(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- cg = (*cg_list)[(*cg_list_len) - 1];
+ cg = (*cgrp_list)[(*cgrp_list_len) - 1];
ret = split_cgroup_name(ctrl_str, cg->name);
if (ret)
return ret;
}
-static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
- int * const cg_list_len, bool first_cg_is_dummy)
+static int parse_opt_args(int argc, char *argv[], struct cgroup **cgrp_list[],
+ int * const cgrp_list_len, bool first_cgrp_is_dummy)
{
struct cgroup *cg = NULL;
int ret = 0;
* The first cgroup was temporarily populated and requires the
* user to provide a cgroup name as an opt
*/
- if (argv[optind] == NULL && first_cg_is_dummy) {
+ if (argv[optind] == NULL && first_cgrp_is_dummy) {
usage(1, argv[0]);
exit(EXIT_BADARGS);
}
* Example of a command that will hit this code:
* $ cgxget -g cpu:mycgroup mycgroup
*/
- if (argv[optind] != NULL && (*cg_list_len) > 0 && strcmp((*cg_list)[0]->name, "") != 0) {
+ if (argv[optind] != NULL && (*cgrp_list_len) > 0 &&
+ strcmp((*cgrp_list)[0]->name, "") != 0) {
usage(1, argv[0]);
exit(EXIT_BADARGS);
}
while (argv[optind] != NULL) {
- if ((*cg_list_len) > 0)
- cg = (*cg_list)[(*cg_list_len) - 1];
+ if ((*cgrp_list_len) > 0)
+ cg = (*cgrp_list)[(*cgrp_list_len) - 1];
else
cg = NULL;
- if ((*cg_list_len) == 0) {
+ if ((*cgrp_list_len) == 0) {
/*
* The user didn't provide a '-r' or '-g' flag.
* The parse_a_flag() function can be reused here
* because we both have the same use case - gather
* all the data about this particular cgroup.
*/
- ret = parse_a_flag(cg_list, cg_list_len);
+ ret = parse_a_flag(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
- sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
+ strncpy((*cgrp_list)[(*cgrp_list_len) - 1]->name, argv[optind],
+ sizeof((*cgrp_list)[(*cgrp_list_len) - 1]->name) - 1);
} else if (cg != NULL && strlen(cg->name) == 0) {
/*
* this cgroup was created based upon control/value
*/
strncpy(cg->name, argv[optind], sizeof(cg->name) - 1);
} else {
- ret = create_cg(cg_list, cg_list_len);
+ ret = create_cg(cgrp_list, cgrp_list_len);
if (ret)
goto out;
- ret = cgroup_copy_cgroup((*cg_list)[(*cg_list_len) - 1],
- (*cg_list)[(*cg_list_len) - 2]);
+ ret = cgroup_copy_cgroup((*cgrp_list)[(*cgrp_list_len) - 1],
+ (*cgrp_list)[(*cgrp_list_len) - 2]);
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
- sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
+ strncpy((*cgrp_list)[(*cgrp_list_len) - 1]->name, argv[optind],
+ sizeof((*cgrp_list)[(*cgrp_list_len) - 1]->name) - 1);
}
optind++;
return ret;
}
-static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * const cg_list_len,
- int * const mode, enum cg_version_t * const version,
- bool * const ignore_unmappable)
+static int parse_opts(int argc, char *argv[], struct cgroup **cgrp_list[],
+ int * const cgrp_list_len, int * const mode,
+ enum cg_version_t * const version, bool * const ignore_unmappable)
{
bool do_not_fill_controller = false;
bool first_cgroup_is_dummy = false;
case 'r':
do_not_fill_controller = true;
first_cgroup_is_dummy = true;
- ret = parse_r_flag(cg_list, cg_list_len, optarg);
+ ret = parse_r_flag(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
break;
fill_controller = true;
if (strchr(optarg, ':') == NULL) {
first_cgroup_is_dummy = true;
- ret = parse_g_flag_no_colon(cg_list, cg_list_len, optarg);
+ ret = parse_g_flag_no_colon(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
} else {
- ret = parse_g_flag_with_colon(cg_list, cg_list_len, optarg);
+ ret = parse_g_flag_with_colon(cgrp_list, cgrp_list_len, optarg);
if (ret)
goto err;
}
break;
case 'a':
fill_controller = true;
- ret = parse_a_flag(cg_list, cg_list_len);
+ ret = parse_a_flag(cgrp_list, cgrp_list_len);
if (ret)
goto err;
break;
exit(EXIT_BADARGS);
}
- ret = parse_opt_args(argc, argv, cg_list, cg_list_len, first_cgroup_is_dummy);
+ ret = parse_opt_args(argc, argv, cgrp_list, cgrp_list_len, first_cgroup_is_dummy);
if (ret)
goto err;
}
#endif /* !LIBCG_LIB */
-static int get_cv_value(struct control_value * const cv, const char * const cg_name,
+static int get_cv_value(struct control_value * const cv, const char * const cgrp_name,
const char * const controller_name)
{
bool is_multiline = false;
void *handle, *tmp;
int ret;
- ret = cgroup_read_value_begin(controller_name, cg_name, cv->name, &handle, tmp_line,
+ ret = cgroup_read_value_begin(controller_name, cgrp_name, cv->name, &handle, tmp_line,
LL_MAX);
if (ret == ECGEOF)
goto read_end;
tmp_ret = cgroup_test_subsys_mounted(controller_name);
if (tmp_ret == 0) {
err("cgxget: cannot find controller '%s' in group '%s'\n",
- controller_name, cg_name);
+ controller_name, cgrp_name);
} else {
err("variable file read failed %s\n", cgroup_strerror(ret));
}
}
#ifndef LIBCG_LIB
-static int get_values(struct cgroup *cg_list[], int cg_list_len)
+static int get_values(struct cgroup *cgrp_list[], int cgrp_list_len)
{
int ret = 0;
int i;
- for (i = 0; i < cg_list_len; i++) {
- ret = get_cgroup_values(cg_list[i]);
+ for (i = 0; i < cgrp_list_len; i++) {
+ ret = get_cgroup_values(cgrp_list[i]);
if (ret)
break;
}
info("\n");
}
-static void print_cgroups(struct cgroup *cg_list[], int cg_list_len, int mode)
+static void print_cgroups(struct cgroup *cgrp_list[], int cgrp_list_len, int mode)
{
int i;
- for (i = 0; i < cg_list_len; i++)
- print_cgroup(cg_list[i], mode);
+ for (i = 0; i < cgrp_list_len; i++)
+ print_cgroup(cgrp_list[i], mode);
}
-static int convert_cgroups(struct cgroup **cg_list[], int cg_list_len,
+static int convert_cgroups(struct cgroup **cgrp_list[], int cgrp_list_len,
enum cg_version_t in_version, enum cg_version_t out_version)
{
- struct cgroup **cg_converted_list;
+ struct cgroup **cgrp_converted_list;
int i = 0, j, ret = 0;
- cg_converted_list = malloc(cg_list_len * sizeof(struct cgroup *));
- if (cg_converted_list == NULL)
+ cgrp_converted_list = malloc(cgrp_list_len * sizeof(struct cgroup *));
+ if (cgrp_converted_list == NULL)
goto out;
- for (i = 0; i < cg_list_len; i++) {
- cg_converted_list[i] = cgroup_new_cgroup((*cg_list)[i]->name);
- if (cg_converted_list[i] == NULL) {
+ for (i = 0; i < cgrp_list_len; i++) {
+ cgrp_converted_list[i] = cgroup_new_cgroup((*cgrp_list)[i]->name);
+ if (cgrp_converted_list[i] == NULL) {
ret = ECGCONTROLLERCREATEFAILED;
goto out;
}
- ret = cgroup_convert_cgroup(cg_converted_list[i], out_version, (*cg_list)[i],
+ ret = cgroup_convert_cgroup(cgrp_converted_list[i], out_version, (*cgrp_list)[i],
in_version);
if (ret)
goto out;
if (ret != 0 && ret != ECGNOVERSIONCONVERT) {
/* The conversion failed */
for (j = 0; j < i; j++)
- cgroup_free(&(cg_converted_list[j]));
- free(cg_converted_list);
+ cgroup_free(&(cgrp_converted_list[j]));
+ free(cgrp_converted_list);
} else {
/*
* The conversion succeeded or was unmappable.
* Free the old list.
*/
- for (i = 0; i < cg_list_len; i++)
- cgroup_free(&(*cg_list)[i]);
+ for (i = 0; i < cgrp_list_len; i++)
+ cgroup_free(&(*cgrp_list)[i]);
- *cg_list = cg_converted_list;
+ *cgrp_list = cgrp_converted_list;
}
return ret;
{
int mode = MODE_SHOW_NAMES | MODE_SHOW_HEADERS;
enum cg_version_t version = CGROUP_UNK;
- struct cgroup **cg_list = NULL;
+ struct cgroup **cgrp_list = NULL;
bool ignore_unmappable = false;
- int cg_list_len = 0;
+ int cgrp_list_len = 0;
int ret = 0, i;
/* No parameter on input? */
mode |= MODE_SYSTEMD_DELEGATE;
#endif
- ret = parse_opts(argc, argv, &cg_list, &cg_list_len, &mode, &version, &ignore_unmappable);
+ ret = parse_opts(argc, argv, &cgrp_list, &cgrp_list_len, &mode, &version,
+ &ignore_unmappable);
if (ret)
goto err;
if (mode & MODE_SYSTEMD_DELEGATE)
cgroup_set_default_systemd_cgroup();
- ret = convert_cgroups(&cg_list, cg_list_len, version, CGROUP_DISK);
+ ret = convert_cgroups(&cgrp_list, cgrp_list_len, version, CGROUP_DISK);
if ((ret && ret != ECGNOVERSIONCONVERT) ||
(ret == ECGNOVERSIONCONVERT && !ignore_unmappable))
/*
*/
goto err;
- ret = get_values(cg_list, cg_list_len);
+ ret = get_values(cgrp_list, cgrp_list_len);
if (ret)
goto err;
- ret = convert_cgroups(&cg_list, cg_list_len, CGROUP_DISK, version);
+ ret = convert_cgroups(&cgrp_list, cgrp_list_len, CGROUP_DISK, version);
if (ret)
goto err;
- print_cgroups(cg_list, cg_list_len, mode);
+ print_cgroups(cgrp_list, cgrp_list_len, mode);
err:
- for (i = 0; i < cg_list_len; i++)
- cgroup_free(&(cg_list[i]));
+ for (i = 0; i < cgrp_list_len; i++)
+ cgroup_free(&(cgrp_list[i]));
return ret;
}
/* cgroup.subtree_control -r name, value */
static struct control_value *cgrp_subtree_ctrl_val;
-static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX])
+static struct cgroup *copy_name_value_from_cgroup(char src_cgrp_path[FILENAME_MAX])
{
- struct cgroup *src_cgroup;
+ struct cgroup *src_cgrp;
int ret = 0;
/* create source cgroup */
- src_cgroup = cgroup_new_cgroup(src_cg_path);
- if (!src_cgroup) {
+ src_cgrp = cgroup_new_cgroup(src_cgrp_path);
+ if (!src_cgrp) {
err("can't create cgroup: %s\n", cgroup_strerror(ECGFAIL));
- goto scgroup_err;
+ goto scgrp_err;
}
/* copy the name-version values to the cgroup structure */
- ret = cgroup_get_cgroup(src_cgroup);
+ ret = cgroup_get_cgroup(src_cgrp);
if (ret != 0) {
- err("cgroup %s error: %s\n", src_cg_path, cgroup_strerror(ret));
- goto scgroup_err;
+ err("cgroup %s error: %s\n", src_cgrp_path, cgroup_strerror(ret));
+ goto scgrp_err;
}
- return src_cgroup;
+ return src_cgrp;
-scgroup_err:
- cgroup_free(&src_cgroup);
+scgrp_err:
+ cgroup_free(&src_cgrp);
return NULL;
}
/*
* If a failure occurs between this comment and the "End of above comment"
- * below, then we need to manually free converted_src_cgroup.
+ * below, then we need to manually free converted_src_cgrp.
*/
ret = cgroup_convert_cgroup(converted_src_cgrp, CGROUP_DISK, src_cgrp, src_version);
}
/*
- * End of above comment about converted_src_cgroup needing to be manually freed.
+ * End of above comment about converted_src_cgrp needing to be manually freed.
*/
cgroup_free(&cgrp);
cgrp = converted_src_cgrp;
int recursive = 0;
int nv_max = 0;
- char src_cg_path[FILENAME_MAX] = "\0";
+ char src_cgrp_path[FILENAME_MAX] = "\0";
struct cgroup *subtree_cgrp = NULL;
- struct cgroup *src_cgroup = NULL;
+ struct cgroup *src_cgrp = NULL;
enum cg_version_t src_version = CGROUP_UNK;
bool ignore_unmappable = false;
goto err;
}
flags |= FL_COPY;
- strncpy(src_cg_path, optarg, FILENAME_MAX);
- src_cg_path[FILENAME_MAX-1] = '\0';
+ strncpy(src_cgrp_path, optarg, FILENAME_MAX);
+ src_cgrp_path[FILENAME_MAX-1] = '\0';
break;
case '1':
src_version = CGROUP_V1;
/* copy the name-value pairs from -r options */
if ((flags & FL_RULES) != 0) {
- src_cgroup = create_cgroup_from_name_value_pairs("tmp", name_value, nv_number);
- if (src_cgroup == NULL)
+ src_cgrp = create_cgroup_from_name_value_pairs("tmp", name_value, nv_number);
+ if (src_cgrp == NULL)
goto err;
if (cgrp_subtree_ctrl_val && !recursive) {
/* copy the name-value from the given group */
if ((flags & FL_COPY) != 0) {
- src_cgroup = copy_name_value_from_cgroup(src_cg_path);
- if (src_cgroup == NULL)
+ src_cgrp = copy_name_value_from_cgroup(src_cgrp_path);
+ if (src_cgrp == NULL)
goto err;
}
while (optind < argc) {
if (recursive) {
- ret = cgroup_set_cgroup_values_r(src_cgroup, argv[optind],
+ ret = cgroup_set_cgroup_values_r(src_cgrp, argv[optind],
ignore_unmappable, src_version);
} else {
ret = cgroup_set_cgroup_values(subtree_cgrp, argv[optind],
ignore_unmappable, src_version);
if (ret)
goto err;
- ret = cgroup_set_cgroup_values(src_cgroup, argv[optind],
+ ret = cgroup_set_cgroup_values(src_cgrp, argv[optind],
ignore_unmappable, src_version);
}
if (ret)
}
err:
- cgroup_free(&src_cgroup);
+ cgroup_free(&src_cgrp);
cgroup_free(&subtree_cgrp);
free(name_value);
* if the info about controller "name" should be printed, then the function
* returns nonzero value
*/
-static int is_ctlr_on_list(struct cgroup_group_spec *cgroup_list, const char *name)
+static int is_ctlr_on_list(struct cgroup_group_spec *cgrp_list, const char *name)
{
int j;
- for (j = 0; cgroup_list->controllers[j] != NULL; j++)
- if (strcmp(cgroup_list->controllers[j], name) == 0)
+ for (j = 0; cgrp_list->controllers[j] != NULL; j++)
+ if (strcmp(cgrp_list->controllers[j], name) == 0)
return 1;
return 0;
/* display controller:/input_path cgroups */
static int display_controller_data(char *input_path, char *controller, char *name)
{
- char cgroup_dir_path[FILENAME_MAX];
char input_dir_path[FILENAME_MAX];
+ char cgrp_dir_path[FILENAME_MAX];
struct cgroup_file_info info;
int lvl, len, ret;
void *handle;
if (ret != 0)
return ret;
- strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX);
- cgroup_dir_path[sizeof(cgroup_dir_path) - 1] = '\0';
+ strncpy(cgrp_dir_path, info.full_path, FILENAME_MAX);
+ cgrp_dir_path[sizeof(cgrp_dir_path) - 1] = '\0';
/* remove problematic '/' characters from cgroup directory path */
- trim_filepath(cgroup_dir_path);
+ trim_filepath(cgrp_dir_path);
strncpy(input_dir_path, input_path, FILENAME_MAX);
input_dir_path[sizeof(input_dir_path) - 1] = '\0';
/* remove problematic '/' characters from input directory path */
trim_filepath(input_dir_path);
- len = strlen(cgroup_dir_path) - strlen(input_dir_path);
+ len = strlen(cgrp_dir_path) - strlen(input_dir_path);
print_info(&info, name, len);
while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) == 0)
* print data about input cgroup_list cgroups if FL_LIST flag is set then
* if the function does not find the cgroup it returns ECGEOF
*/
-static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
+static int print_cgroup(struct cgroup_group_spec *cgrp_spec, int flags)
{
struct cgroup_mount_point controller;
char all_conts[FILENAME_MAX];
} else {
/* we got new mount point, print it if needed */
if (output) {
- ret = display_controller_data(cgroup_spec->path, con_name,
- all_conts);
+ ret = display_controller_data(cgrp_spec->path, con_name, all_conts);
if (ret)
return ret;
if ((flags & FL_LIST) != 0) {
/* set output flag */
if ((output == 0) && (!(flags & FL_LIST) ||
- (is_ctlr_on_list(cgroup_spec, controller.name))))
+ (is_ctlr_on_list(cgrp_spec, controller.name))))
output = 1;
/* the actual controller should not be printed */
return ret;
if (output)
- ret = display_controller_data(cgroup_spec->path, con_name, all_conts);
+ ret = display_controller_data(cgrp_spec->path, con_name, all_conts);
return ret;
}
-static int cgroup_list_cgroups(char *tname, struct cgroup_group_spec *cgroup_list[], int flags)
+static int cgroup_list_cgroups(char *tname, struct cgroup_group_spec *cgrp_list[], int flags)
{
int final_ret = 0;
int ret = 0;
}
if ((flags & FL_LIST) == 0) {
- struct cgroup_group_spec *cgroup_spec;
+ struct cgroup_group_spec *cgrp_spec;
- cgroup_spec = calloc(1, sizeof(struct cgroup_group_spec));
+ cgrp_spec = calloc(1, sizeof(struct cgroup_group_spec));
/* we have to print all cgroups */
- ret = print_cgroup(cgroup_spec, flags);
- free(cgroup_spec);
+ ret = print_cgroup(cgrp_spec, flags);
+ free(cgrp_spec);
if (ret == 0) {
final_ret = 0;
} else {
}
} else {
/* we have he list of controllers which should be print */
- while ((cgroup_list[i] != NULL) && ((ret == ECGEOF) || (ret == 0))) {
+ while ((cgrp_list[i] != NULL) && ((ret == ECGEOF) || (ret == 0))) {
- ret = print_cgroup(cgroup_list[i], flags);
+ ret = print_cgroup(cgrp_list[i], flags);
if (ret != 0) {
if (ret == ECGEOF) {
/* controller was not found */
}
err("%s: cannot find group %s..:%s: %s\n", tname,
- cgroup_list[i]->controllers[0], cgroup_list[i]->path,
+ cgrp_list[i]->controllers[0], cgrp_list[i]->path,
cgroup_strerror(final_ret));
}
i++;
{0, 0, 0, 0}
};
- struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
+ struct cgroup_group_spec *cgrp_list[CG_HIER_MAX];
#ifdef WITH_SYSTEMD
int ignore_default_systemd_delegate_slice = 0;
#endif
int c;
int i;
- memset(cgroup_list, 0, sizeof(cgroup_list));
+ memset(cgrp_list, 0, sizeof(cgrp_list));
/* parse arguments */
#ifdef WITH_SYSTEMD
ret = 0;
goto err;
case 'g':
- ret = parse_cgroup_spec(cgroup_list, optarg, CG_HIER_MAX);
+ ret = parse_cgroup_spec(cgrp_list, optarg, CG_HIER_MAX);
if (ret) {
err("%s: cgroup controller and path parsing failed (%s)\n",
argv[0], optarg);
/* read the list of controllers */
while (optind < argc) {
- ret = parse_cgroup_spec(cgroup_list, argv[optind], CG_HIER_MAX);
+ ret = parse_cgroup_spec(cgrp_list, argv[optind], CG_HIER_MAX);
if (ret) {
err("%s: cgroup controller an path parsing failed (%s)\n", argv[0],
argv[optind]);
optind++;
}
- if (cgroup_list[0] != NULL) {
+ if (cgrp_list[0] != NULL) {
/* cgroups on input */
flags |= FL_LIST;
}
/* print the information based on list of input cgroups and flags */
- ret = cgroup_list_cgroups(argv[0], cgroup_list, flags);
+ ret = cgroup_list_cgroups(argv[0], cgrp_list, flags);
err:
- if (cgroup_list[0]) {
+ if (cgrp_list[0]) {
for (i = 0; i < CG_HIER_MAX; i++) {
- if (cgroup_list[i])
- cgroup_free_group_spec(cgroup_list[i]);
+ if (cgrp_list[i])
+ cgroup_free_group_spec(cgrp_list[i]);
}
}