1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 00:51:24 +03:00

core: simplify %r and %R logic a bit

Do not calculate the cgroup path manually, just use normal unit fields
and calls for that.
This commit is contained in:
Lennart Poettering 2015-04-30 12:33:54 +02:00
parent c96cc5822c
commit 696fd1ef4f

View File

@ -128,26 +128,35 @@ static int specifier_cgroup(char specifier, void *data, void *userdata, char **r
static int specifier_cgroup_root(char specifier, void *data, void *userdata, char **ret) { static int specifier_cgroup_root(char specifier, void *data, void *userdata, char **ret) {
Unit *u = userdata; Unit *u = userdata;
const char *slice;
char *n; char *n;
int r;
assert(u); assert(u);
slice = unit_slice_name(u);
if (specifier == 'R' || !slice)
n = strdup(u->manager->cgroup_root); n = strdup(u->manager->cgroup_root);
else {
_cleanup_free_ char *p = NULL;
r = cg_slice_to_path(slice, &p);
if (r < 0)
return r;
n = strjoin(u->manager->cgroup_root, "/", p, NULL);
if (!n) if (!n)
return -ENOMEM; return -ENOMEM;
}
*ret = n;
return 0;
}
static int specifier_cgroup_slice(char specifier, void *data, void *userdata, char **ret) {
Unit *u = userdata;
char *n;
assert(u);
if (UNIT_ISSET(u->slice)) {
Unit *slice;
slice = UNIT_DEREF(u->slice);
if (slice->cgroup_path)
n = strdup(slice->cgroup_path);
else
n = unit_default_cgroup_path(slice);
} else
n = strdup(u->manager->cgroup_root);
*ret = n; *ret = n;
return 0; return 0;
@ -392,7 +401,7 @@ int unit_full_printf(Unit *u, const char *format, char **ret) {
{ 'f', specifier_filename, NULL }, { 'f', specifier_filename, NULL },
{ 'c', specifier_cgroup, NULL }, { 'c', specifier_cgroup, NULL },
{ 'r', specifier_cgroup_root, NULL }, { 'r', specifier_cgroup_slice, NULL },
{ 'R', specifier_cgroup_root, NULL }, { 'R', specifier_cgroup_root, NULL },
{ 't', specifier_runtime, NULL }, { 't', specifier_runtime, NULL },
{ 'U', specifier_user_name, NULL }, { 'U', specifier_user_name, NULL },