diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-15 15:34:35 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-15 18:20:57 +0200 |
commit | db21bf5ae965a702a6cf8caa3ed74e0766986944 (patch) | |
tree | 172f03b11e96b8544ab8e6aaa00c9f6ed108485b /src/shared/dropin.c | |
parent | fileio: clean up write_string_file() naming (diff) | |
download | systemd-db21bf5ae965a702a6cf8caa3ed74e0766986944.tar.xz systemd-db21bf5ae965a702a6cf8caa3ed74e0766986944.zip |
shared: modernize drop_in_file() a bit
Make the return parameters optional, since we don't actually need them
in all cases (see later commits).
Diffstat (limited to '')
-rw-r--r-- | src/shared/dropin.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c index c3050634bd..de93e120e0 100644 --- a/src/shared/dropin.c +++ b/src/shared/dropin.c @@ -31,14 +31,11 @@ int drop_in_file( char **ret_unit_dir, char **ret_path) { - char prefix[DECIMAL_STR_MAX(unsigned) + 1] = {}; - _cleanup_free_ char *n = NULL, *unit_dir = NULL, *path = NULL; + _cleanup_free_ char *n = NULL, *unit_dir = NULL; assert(dir); assert(unit); assert(name); - assert(ret_unit_dir); - assert(ret_path); n = xescape(name, "/."); if (!n) @@ -46,16 +43,28 @@ int drop_in_file( if (!filename_is_valid(n)) return -EINVAL; - if (level != UINT_MAX) - xsprintf(prefix, "%u-", level); + if (ret_unit_dir || ret_path) { + unit_dir = path_join(dir, strjoina(unit, ".d")); + if (!unit_dir) + return -ENOMEM; + } - unit_dir = path_join(dir, strjoina(unit, ".d")); - path = strjoin(unit_dir, "/", prefix, n, ".conf"); - if (!unit_dir || !path) - return -ENOMEM; + if (ret_path) { + char prefix[DECIMAL_STR_MAX(unsigned) + 1] = {}; + + if (level != UINT_MAX) + xsprintf(prefix, "%u-", level); + + _cleanup_free_ char *path = strjoin(unit_dir, "/", prefix, n, ".conf"); + if (!path) + return -ENOMEM; + + *ret_path = TAKE_PTR(path); + } + + if (ret_unit_dir) + *ret_unit_dir = TAKE_PTR(unit_dir); - *ret_unit_dir = TAKE_PTR(unit_dir); - *ret_path = TAKE_PTR(path); return 0; } |