diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-05-11 16:42:24 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2024-05-11 19:46:15 +0200 |
commit | 82c2214539c9d65c029f4658c9cf2c7be53b9480 (patch) | |
tree | d6a7c968636b2181bcfb96586b0f40b405b6810c /src/debug-generator | |
parent | Merge pull request #32755 from yuwata/test-network-cleanups (diff) | |
download | systemd-82c2214539c9d65c029f4658c9cf2c7be53b9480.tar.xz systemd-82c2214539c9d65c029f4658c9cf2c7be53b9480.zip |
debug-generator: Allow specifying name of unit-dropin credential
A fixed name is too rigid, let's give users the ability to define
custom drop-in names which at the same time also allows defining
multiple dropins per unit.
We use ~ as the separator because:
- ':' is not allowed in credential names
- '=' is used to separate credential from value in mkosi's --credential
argument.
- '-' is commonly used in filenames
- '@' already has meaning as the unit template specifier which might be
confusing when adding dropins for template units
Diffstat (limited to 'src/debug-generator')
-rw-r--r-- | src/debug-generator/debug-generator.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 1b14f1222a..7637980689 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -185,12 +185,6 @@ static int process_unit_credentials(const char *credentials_dir) { if (!unit && !dropin) continue; - if (!unit_name_is_valid(unit ?: dropin, UNIT_NAME_ANY)) { - log_warning("Invalid unit name '%s' in credential '%s', ignoring.", - unit ?: dropin, de->d_name); - continue; - } - _cleanup_free_ char *d = NULL; r = read_credential_with_decryption(de->d_name, (void**) &d, NULL); @@ -202,6 +196,12 @@ static int process_unit_credentials(const char *credentials_dir) { if (unit) { _cleanup_free_ char *p = NULL; + if (!unit_name_is_valid(unit, UNIT_NAME_ANY)) { + log_warning("Invalid unit name '%s' in credential '%s', ignoring.", + unit, de->d_name); + continue; + } + p = path_join(arg_dest, unit); if (!p) return log_oom(); @@ -216,14 +216,35 @@ static int process_unit_credentials(const char *credentials_dir) { log_debug("Wrote unit file '%s' from credential '%s'", unit, de->d_name); } else if (dropin) { - r = write_drop_in(arg_dest, dropin, 50, "credential", d); + _cleanup_free_ char *dropin_unit = NULL; + const char *tilde, *dropin_name; + + tilde = strchrnul(dropin, '~'); + dropin_unit = strndup(dropin, tilde - dropin); + if (!dropin_unit) + return log_oom(); + + if (!unit_name_is_valid(dropin_unit, UNIT_NAME_ANY)) { + log_warning("Invalid unit name '%s' in credential '%s', ignoring.", + dropin_unit, de->d_name); + continue; + } + + dropin_name = isempty(tilde) ? "50-credential" : tilde + 1; + if (isempty(dropin_name)) { + log_warning("Empty drop-in name for unit '%s' in credential '%s', ignoring.", + dropin_unit, de->d_name); + continue; + } + + r = write_drop_in(arg_dest, dropin_unit, /* level = */ UINT_MAX, dropin_name, d); if (r < 0) { - log_warning_errno(r, "Failed to write drop-in for unit '%s' from credential '%s', ignoring: %m", - dropin, de->d_name); + log_warning_errno(r, "Failed to write drop-in '%s' for unit '%s' from credential '%s', ignoring: %m", + dropin_name, dropin_unit, de->d_name); continue; } - log_debug("Wrote drop-in for unit '%s' from credential '%s'", dropin, de->d_name); + log_debug("Wrote drop-in '%s' for unit '%s' from credential '%s'", dropin_name, dropin_unit, de->d_name); } else assert_not_reached(); } |