]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: rework unit_find_template_path() to follow coding style
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Nov 2018 16:06:03 +0000 (17:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 29 Nov 2018 10:25:32 +0000 (11:25 +0100)
This makes sure that we don't clobber return values on failure and reset
all return values on success.

src/systemctl/systemctl.c

index 490b739f9e43bf4d0800bf16a4c6c3a3e1fdddce..ac55ec6c8b5e56cf7f90ee73ba668bb267bbfdfb 100644 (file)
@@ -2452,30 +2452,43 @@ static int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **re
 static int unit_find_template_path(
                 const char *unit_name,
                 LookupPaths *lp,
-                char **fragment_path,
-                char **template) {
+                char **ret_fragment_path,
+                char **ret_template) {
 
-        _cleanup_free_ char *_template = NULL;
+        _cleanup_free_ char *t = NULL, *f = NULL;
         int r;
 
         /* Returns 1 if a fragment was found, 0 if not found, negative on error. */
 
-        r = unit_file_find_path(lp, unit_name, fragment_path);
-        if (r != 0)
-                return r; /* error or found a real unit */
+        r = unit_file_find_path(lp, unit_name, &f);
+        if (r < 0)
+                return r;
+        if (r > 0) {
+                if (ret_fragment_path)
+                        *ret_fragment_path = TAKE_PTR(f);
+                if (ret_template)
+                        *ret_template = NULL;
+                return r; /* found a real unit */
+        }
+
+        r = unit_name_template(unit_name, &t);
+        if (r == -EINVAL) {
+                if (ret_fragment_path)
+                        *ret_fragment_path = NULL;
+                if (ret_template)
+                        *ret_template = NULL;
 
-        r = unit_name_template(unit_name, &_template);
-        if (r == -EINVAL)
                 return 0; /* not a template, does not exist */
+        }
         if (r < 0)
                 return log_error_errno(r, "Failed to determine template name: %m");
 
-        r = unit_file_find_path(lp, _template, fragment_path);
+        r = unit_file_find_path(lp, t, ret_fragment_path);
         if (r < 0)
                 return r;
 
-        if (template)
-                *template = TAKE_PTR(_template);
+        if (ret_template)
+                *ret_template = r > 0 ? TAKE_PTR(t) : NULL;
 
         return r;
 }