basic/cgroup-util: modernize cg_split_spec()
Those cryptic one letter variable names, yuck!
This commit is contained in:
parent
b35e9974fa
commit
2a8020fe9d
|
@ -878,9 +878,8 @@ int cg_is_empty_recursive(const char *controller, const char *path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cg_split_spec(const char *spec, char **controller, char **path) {
|
int cg_split_spec(const char *spec, char **ret_controller, char **ret_path) {
|
||||||
char *t = NULL, *u = NULL;
|
_cleanup_free_ char *controller = NULL, *path = NULL;
|
||||||
const char *e;
|
|
||||||
|
|
||||||
assert(spec);
|
assert(spec);
|
||||||
|
|
||||||
|
@ -888,76 +887,53 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
|
||||||
if (!path_is_normalized(spec))
|
if (!path_is_normalized(spec))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (path) {
|
if (ret_path) {
|
||||||
t = strdup(spec);
|
path = strdup(spec);
|
||||||
if (!t)
|
if (!path)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*path = path_simplify(t, false);
|
path_simplify(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller)
|
} else {
|
||||||
*controller = NULL;
|
const char *e;
|
||||||
|
|
||||||
return 0;
|
e = strchr(spec, ':');
|
||||||
}
|
if (e) {
|
||||||
|
controller = strndup(spec, e-spec);
|
||||||
e = strchr(spec, ':');
|
if (!controller)
|
||||||
if (!e) {
|
|
||||||
if (!cg_controller_is_valid(spec))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (controller) {
|
|
||||||
t = strdup(spec);
|
|
||||||
if (!t)
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
if (!cg_controller_is_valid(controller))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
*controller = t;
|
if (!isempty(e + 1)) {
|
||||||
|
path = strdup(e+1);
|
||||||
|
if (!path)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (!path_is_normalized(path) ||
|
||||||
|
!path_is_absolute(path))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
path_simplify(path, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!cg_controller_is_valid(spec))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (ret_controller) {
|
||||||
|
controller = strdup(spec);
|
||||||
|
if (!controller)
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path)
|
|
||||||
*path = NULL;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t = strndup(spec, e-spec);
|
if (ret_controller)
|
||||||
if (!t)
|
*ret_controller = TAKE_PTR(controller);
|
||||||
return -ENOMEM;
|
if (ret_path)
|
||||||
if (!cg_controller_is_valid(t)) {
|
*ret_path = TAKE_PTR(path);
|
||||||
free(t);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isempty(e+1))
|
|
||||||
u = NULL;
|
|
||||||
else {
|
|
||||||
u = strdup(e+1);
|
|
||||||
if (!u) {
|
|
||||||
free(t);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!path_is_normalized(u) ||
|
|
||||||
!path_is_absolute(u)) {
|
|
||||||
free(t);
|
|
||||||
free(u);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
path_simplify(u, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (controller)
|
|
||||||
*controller = t;
|
|
||||||
else
|
|
||||||
free(t);
|
|
||||||
|
|
||||||
if (path)
|
|
||||||
*path = u;
|
|
||||||
else
|
|
||||||
free(u);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ typedef int (*cg_kill_log_func_t)(pid_t pid, int sig, void *userdata);
|
||||||
int cg_kill(const char *controller, const char *path, int sig, CGroupFlags flags, Set *s, cg_kill_log_func_t kill_log, void *userdata);
|
int cg_kill(const char *controller, const char *path, int sig, CGroupFlags flags, Set *s, cg_kill_log_func_t kill_log, void *userdata);
|
||||||
int cg_kill_recursive(const char *controller, const char *path, int sig, CGroupFlags flags, Set *s, cg_kill_log_func_t kill_log, void *userdata);
|
int cg_kill_recursive(const char *controller, const char *path, int sig, CGroupFlags flags, Set *s, cg_kill_log_func_t kill_log, void *userdata);
|
||||||
|
|
||||||
int cg_split_spec(const char *spec, char **controller, char **path);
|
int cg_split_spec(const char *spec, char **ret_controller, char **ret_path);
|
||||||
int cg_mangle_path(const char *path, char **result);
|
int cg_mangle_path(const char *path, char **result);
|
||||||
|
|
||||||
int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs);
|
int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs);
|
||||||
|
|
Loading…
Reference in a new issue