summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 12:33:54 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-30 12:33:54 +0200
commit696fd1ef4f2f8574e349332a16987c6772641edd (patch)
tree2ae0b05a2dc2ed52fd695be271faa517a1fe22f0
parentc96cc5822c165e86be78ed96dac6573986032fab (diff)
core: simplify %r and %R logic a bit
Do not calculate the cgroup path manually, just use normal unit fields and calls for that.
-rw-r--r--src/core/unit-printf.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index bb4aa2121d..5513fe7d9c 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -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) {
Unit *u = userdata;
- const char *slice;
char *n;
- int r;
assert(u);
- slice = unit_slice_name(u);
- if (specifier == 'R' || !slice)
- n = strdup(u->manager->cgroup_root);
- else {
- _cleanup_free_ char *p = NULL;
+ n = strdup(u->manager->cgroup_root);
+ if (!n)
+ return -ENOMEM;
- r = cg_slice_to_path(slice, &p);
- if (r < 0)
- return r;
+ *ret = n;
+ return 0;
+}
- n = strjoin(u->manager->cgroup_root, "/", p, NULL);
- if (!n)
- return -ENOMEM;
- }
+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;
return 0;
@@ -392,7 +401,7 @@ int unit_full_printf(Unit *u, const char *format, char **ret) {
{ 'f', specifier_filename, NULL },
{ 'c', specifier_cgroup, NULL },
- { 'r', specifier_cgroup_root, NULL },
+ { 'r', specifier_cgroup_slice, NULL },
{ 'R', specifier_cgroup_root, NULL },
{ 't', specifier_runtime, NULL },
{ 'U', specifier_user_name, NULL },