From 115cbf7e209a86cf5317fa12d44566247b4af332 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sat, 24 Oct 2015 20:55:56 +0000 Subject: [PATCH] core: various small fixes to unit-printf * check memory allocation errors in specifier_cgroup_slice * %I doesn't fail for non-instantiated units (%i doesn't fail too) * EOPNOTSUPP for consistency --- src/core/unit-printf.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 0889769..f327953 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -63,10 +63,7 @@ static int specifier_instance_unescaped(char specifier, void *data, void *userda assert(u); - if (!u->instance) - return -EINVAL; - - return unit_name_unescape(u->instance, ret); + return unit_name_unescape(strempty(u->instance), ret); } static int specifier_filename(char specifier, void *data, void *userdata, char **ret) { @@ -128,6 +125,8 @@ static int specifier_cgroup_slice(char specifier, void *data, void *userdata, ch n = unit_default_cgroup_path(slice); } else n = strdup(u->manager->cgroup_root); + if (!n) + return -ENOMEM; *ret = n; return 0; @@ -166,7 +165,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char c = unit_get_exec_context(u); if (!c) - return -EINVAL; + return -EOPNOTSUPP; if (u->manager->running_as == MANAGER_SYSTEM) { -- 2.7.4