temp = strtok_r(NULL, ",", &saveptr);
if (temp) {
- controllers[j] = (char *) malloc(strlen(temp) + 1);
+ controllers[j] = strdup(temp);
if (!controllers[j])
return ECGOTHER;
- else
- strcpy(controllers[j], temp);
}
j++;
} while (temp);
return 0;
}
- if (i == 3) {
+ if (i == CGRULES_MAX_FIELDS_PER_LINE) {
/* a complete line */
if (((strcmp(cgrldp->pw->pw_name, user) == 0) ||
(strcmp(user, "*") == 0)) ||
(match_uid && !strcmp(user, "%"))) {
match_uid = 1;
- cgroup = (struct cgroup *)
- calloc(1, sizeof(struct cgroup));
+ cgroup = calloc(1, sizeof(struct cgroup));
if (!cgroup) {
ret = ECGOTHER;
goto out;
(match_gid && !strcmp(user, "%"))) {
match_gid = 1;
- cgroup = (struct cgroup *)
- calloc(1, sizeof(struct cgroup));
+ cgroup = calloc(1,
+ sizeof(struct cgroup));
if (!cgroup) {
ret = ECGOTHER;
goto out;
int ret = 0, i;
struct passwd *pw;
struct cgroup_rules_data cgrld, *cgrldp = &cgrld;
- struct cgroup *cgroups[CG_CONTROLLER_MAX];
+ struct cgroup *cgroups[CG_HIER_MAX];
if (!cgroup_initialized) {
dbg("libcgroup is not initialized\n");
return ECGROUPNOTINITIALIZED;
}
memset(cgrldp, 0, sizeof(struct cgroup_rules_data));
- memset(cgroups, 0, CG_CONTROLLER_MAX);
+ memset(cgroups, 0, CG_HIER_MAX);
pw = getpwuid(uid);
if (!pw) {
}
/* Add task to cgroups */
- for (i = 0; (i < CG_CONTROLLER_MAX) && cgroups[i]; i++) {
+ for (i = 0; (i < CG_HIER_MAX) && cgroups[i]; i++) {
ret = cgroup_attach_task_pid(cgroups[i], cgrldp->pid);
if (ret) {
dbg("cgroup_attach_task_pid failed:%d\n", ret);
}
out:
/* Free the cgroups */
- for (i = 0; (i < CG_CONTROLLER_MAX) && cgroups[i]; i++)
+ for (i = 0; (i < CG_HIER_MAX) && cgroups[i]; i++)
cgroup_free(&cgroups[i]);
return ret;
}