diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-11-27 17:06:03 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-11-29 11:25:32 +0100 |
commit | b03677e2da759c1f99aedb7766bf086c484b33ab (patch) | |
tree | 3814abc6398221551f6f61213b7fac2f7c9dc958 /src/systemctl | |
parent | f67cb270606c46b3d5700dbea9cde2bc8ff0df63 (diff) | |
download | systemd-b03677e2da759c1f99aedb7766bf086c484b33ab.tar.gz |
systemctl: rework unit_find_template_path() to follow coding style
This makes sure that we don't clobber return values on failure and reset
all return values on success.
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 490b739f9e..ac55ec6c8b 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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; } |