]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
debug-generator: clean up logging and such for units passed from creds 32710/head
authorMike Yuan <me@yhndnzj.com>
Wed, 8 May 2024 10:18:33 +0000 (18:18 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 8 May 2024 10:43:50 +0000 (18:43 +0800)
src/debug-generator/debug-generator.c

index eeefed0eefb26874e9817b815c51babcf998ad8d..1b14f1222abd1d9b80c9455918067850c0c18b2c 100644 (file)
@@ -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;