summaryrefslogtreecommitdiffstats
path: root/src/shared/dropin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/dropin.c')
-rw-r--r--src/shared/dropin.c33
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;
}