From f9e2b42b16b97e1a60a58a49310a86768e45d79f Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 8 May 2024 18:18:33 +0800 Subject: [PATCH] debug-generator: clean up logging and such for units passed from creds --- src/debug-generator/debug-generator.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index eeefed0eefb..1b14f1222ab 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -163,17 +163,16 @@ static int install_debug_shell_dropin(void) { } static int process_unit_credentials(const char *credentials_dir) { + _cleanup_free_ DirectoryEntries *des = NULL; int r; assert(credentials_dir); - _cleanup_free_ DirectoryEntries *des = NULL; r = readdir_all_at(AT_FDCWD, credentials_dir, RECURSE_DIR_SORT|RECURSE_DIR_IGNORE_DOT|RECURSE_DIR_ENSURE_TYPE, &des); if (r < 0) return log_error_errno(r, "Failed to enumerate credentials from credentials directory '%s': %m", credentials_dir); FOREACH_ARRAY(i, des->entries, des->n_entries) { - _cleanup_free_ void *d = NULL; struct dirent *de = *i; const char *unit, *dropin; @@ -192,9 +191,13 @@ static int process_unit_credentials(const char *credentials_dir) { continue; } - r = read_credential_with_decryption(de->d_name, &d, NULL); - if (r < 0) + _cleanup_free_ char *d = NULL; + + r = read_credential_with_decryption(de->d_name, (void**) &d, NULL); + if (r < 0) { + log_warning_errno(r, "Failed to read credential '%s', ignoring: %m", de->d_name); continue; + } if (unit) { _cleanup_free_ char *p = NULL; @@ -212,7 +215,7 @@ static int process_unit_credentials(const char *credentials_dir) { log_debug("Wrote unit file '%s' from credential '%s'", unit, de->d_name); - } else { + } else if (dropin) { r = write_drop_in(arg_dest, dropin, 50, "credential", d); if (r < 0) { log_warning_errno(r, "Failed to write drop-in for unit '%s' from credential '%s', ignoring: %m", @@ -221,7 +224,8 @@ static int process_unit_credentials(const char *credentials_dir) { } log_debug("Wrote drop-in for unit '%s' from credential '%s'", dropin, de->d_name); - } + } else + assert_not_reached(); } return 0; -- 2.47.3