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).
This commit is contained in:
+21
-12
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user