From 045d94248d75bf8db00af7ee970bf8a5cc934e86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 19 Mar 2024 23:36:37 +0100 Subject: [PATCH] core: use strdup_to() Those are all pretty straightforward. --- src/core/service.c | 11 +++-------- src/core/unit-printf.c | 43 +++++++++--------------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index a9047be1caf..10de379ce29 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -5007,14 +5007,9 @@ int service_determine_exec_selinux_label(Service *s, char **ret) { /* Returns the SELinux label used for execution of the main service binary */ - if (s->exec_context.selinux_context) { /* Prefer the explicitly configured label if there is one */ - char *con = strdup(s->exec_context.selinux_context); - if (!con) - return -ENOMEM; - - *ret = con; - return 0; - } + if (s->exec_context.selinux_context) + /* Prefer the explicitly configured label if there is one */ + return strdup_to(ret, s->exec_context.selinux_context); if (s->exec_context.root_image || s->exec_context.n_extension_images > 0 || diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 40267531d12..f25e2e39861 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -91,37 +91,22 @@ static int specifier_cgroup(char specifier, const void *data, const char *root, bad_specifier(u, specifier); - if (crt && crt->cgroup_path) { - char *n; - - n = strdup(crt->cgroup_path); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; - } + if (crt && crt->cgroup_path) + return strdup_to(ret, crt->cgroup_path); return unit_default_cgroup_path(u, ret); } static int specifier_cgroup_root(char specifier, const void *data, const char *root, const void *userdata, char **ret) { const Unit *u = ASSERT_PTR(userdata); - char *n; bad_specifier(u, specifier); - n = strdup(u->manager->cgroup_root); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; + return strdup_to(ret, u->manager->cgroup_root); } static int specifier_cgroup_slice(char specifier, const void *data, const char *root, const void *userdata, char **ret) { const Unit *u = ASSERT_PTR(userdata), *slice; - char *n; bad_specifier(u, specifier); @@ -130,28 +115,18 @@ static int specifier_cgroup_slice(char specifier, const void *data, const char * CGroupRuntime *crt = unit_get_cgroup_runtime(slice); if (crt && crt->cgroup_path) - n = strdup(crt->cgroup_path); - else - return unit_default_cgroup_path(slice, ret); - } else - n = strdup(u->manager->cgroup_root); - if (!n) - return -ENOMEM; + return strdup_to(ret, crt->cgroup_path); - *ret = n; - return 0; + return unit_default_cgroup_path(slice, ret); + } + + return strdup_to(ret, u->manager->cgroup_root); } static int specifier_special_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret) { const Unit *u = ASSERT_PTR(userdata); - char *n; - n = strdup(u->manager->prefix[PTR_TO_UINT(data)]); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; + return strdup_to(ret, u->manager->prefix[PTR_TO_UINT(data)]); } static int specifier_credentials_dir(char specifier, const void *data, const char *root, const void *userdata, char **ret) { -- 2.47.3