From: Lennart Poettering Date: Tue, 15 Oct 2024 13:34:35 +0000 (+0200) Subject: shared: modernize drop_in_file() a bit X-Git-Tag: v257-rc1~212^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db21bf5ae965a702a6cf8caa3ed74e0766986944;p=thirdparty%2Fsystemd.git 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). --- diff --git a/src/shared/dropin.c b/src/shared/dropin.c index c3050634bd3..de93e120e09 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; }