diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-02-11 13:23:32 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-02-11 13:36:39 +0100 |
commit | a561253f0bea9dc584bf369662f6107af0a28c96 (patch) | |
tree | 703ae7326f8a082501f1780de7715274d67f65b3 /src/basic/cgroup-util.c | |
parent | 1b42022388f7c87929dfa37717a14b7c25fac965 (diff) | |
download | systemd-a561253f0bea9dc584bf369662f6107af0a28c96.tar.gz |
cgroup-util: minor modernizations
Rename return parameters to "ret", use ternary op without second
argument, rebreak comments, use isempty() more.
Diffstat (limited to 'src/basic/cgroup-util.c')
-rw-r--r-- | src/basic/cgroup-util.c | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index a626ecf2e2..1890cb09ff 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -462,14 +462,11 @@ int cg_kill_recursive( } static const char *controller_to_dirname(const char *controller) { - const char *e; - assert(controller); - /* Converts a controller name to the directory name below - * /sys/fs/cgroup/ we want to mount it to. Effectively, this - * just cuts off the name= prefixed used for named - * hierarchies, if it is specified. */ + /* Converts a controller name to the directory name below /sys/fs/cgroup/ we want to mount it + * to. Effectively, this just cuts off the name= prefixed used for named hierarchies, if it is + * specified. */ if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) { if (cg_hybrid_unified() > 0) @@ -478,18 +475,14 @@ static const char *controller_to_dirname(const char *controller) { controller = SYSTEMD_CGROUP_CONTROLLER_LEGACY; } - e = startswith(controller, "name="); - if (e) - return e; - - return controller; + return startswith(controller, "name=") ?: controller; } -static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **fs) { +static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **ret) { const char *dn; char *t = NULL; - assert(fs); + assert(ret); assert(controller); dn = controller_to_dirname(controller); @@ -505,14 +498,14 @@ static int join_path_legacy(const char *controller, const char *path, const char if (!t) return -ENOMEM; - *fs = t; + *ret = t; return 0; } -static int join_path_unified(const char *path, const char *suffix, char **fs) { +static int join_path_unified(const char *path, const char *suffix, char **ret) { char *t; - assert(fs); + assert(ret); if (isempty(path) && isempty(suffix)) t = strdup("/sys/fs/cgroup"); @@ -525,34 +518,34 @@ static int join_path_unified(const char *path, const char *suffix, char **fs) { if (!t) return -ENOMEM; - *fs = t; + *ret = t; return 0; } -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 **ret) { int r; - assert(fs); + assert(ret); if (!controller) { char *t; - /* If no controller is specified, we return the path - * *below* the controllers, without any prefix. */ + /* If no controller is specified, we return the path *below* the controllers, without any + * prefix. */ if (!path && !suffix) return -EINVAL; - if (!suffix) + if (isempty(suffix)) t = strdup(path); - else if (!path) + else if (isempty(path)) t = strdup(suffix); else t = path_join(path, suffix); if (!t) return -ENOMEM; - *fs = path_simplify(t); + *ret = path_simplify(t); return 0; } @@ -563,13 +556,13 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch if (r < 0) return r; if (r > 0) - r = join_path_unified(path, suffix, fs); + r = join_path_unified(path, suffix, ret); else - r = join_path_legacy(controller, path, suffix, fs); + r = join_path_legacy(controller, path, suffix, ret); if (r < 0) return r; - path_simplify(*fs); + path_simplify(*ret); return 0; } |