]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: use strdup_to()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Mar 2024 22:36:37 +0000 (23:36 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 20 Mar 2024 14:18:21 +0000 (15:18 +0100)
Those are all pretty straightforward.

src/core/service.c
src/core/unit-printf.c

index a9047be1cafdb2a698847f4393e579a75b55f1bf..10de379ce29172b1489d8d3a35d628953ec7c254 100644 (file)
@@ -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 ||
index 40267531d12b9fb9bcdf939d980693b387dc86c2..f25e2e39861b7f0bda1416caa1fa18bfe53ec6c1 100644 (file)
@@ -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) {