ac3a84
From e44e907f58d3c89e0de01e8ff4e25079f1ca505e Mon Sep 17 00:00:00 2001
ac3a84
From: Luca Boccassi <bluca@debian.org>
ac3a84
Date: Wed, 23 Nov 2022 16:06:48 +0000
ac3a84
Subject: [PATCH] portable: add a few more useful debug log messages
ac3a84
ac3a84
When attaching and /etc/systemd/system.attached can't be created or used
ac3a84
(eg: dead symlink) the logs are pretty much useless as even at debug
ac3a84
level there's no indication of what is going wrong.
ac3a84
Add some debug logs, and return a more specific error string over D-Bus.
ac3a84
ac3a84
(cherry picked from commit 80d95fcd6e1947a7887b96b22a32dbca115baac9)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/portable/portable.c | 6 +++---
ac3a84
 1 file changed, 3 insertions(+), 3 deletions(-)
ac3a84
ac3a84
diff --git a/src/portable/portable.c b/src/portable/portable.c
ac3a84
index be906f786c..fbc4497014 100644
ac3a84
--- a/src/portable/portable.c
ac3a84
+++ b/src/portable/portable.c
ac3a84
@@ -1131,7 +1131,7 @@ static int attach_unit_file(
ac3a84
         (void) mkdir_parents(where, 0755);
ac3a84
         if (mkdir(where, 0755) < 0) {
ac3a84
                 if (errno != EEXIST)
ac3a84
-                        return -errno;
ac3a84
+                        return log_debug_errno(errno, "Failed to create attach directory %s: %m", where);
ac3a84
         } else
ac3a84
                 (void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, where, NULL);
ac3a84
 
ac3a84
@@ -1145,7 +1145,7 @@ static int attach_unit_file(
ac3a84
 
ac3a84
         if (mkdir(dropin_dir, 0755) < 0) {
ac3a84
                 if (errno != EEXIST)
ac3a84
-                        return -errno;
ac3a84
+                        return log_debug_errno(errno, "Failed to create drop-in directory %s: %m", dropin_dir);
ac3a84
         } else
ac3a84
                 (void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, dropin_dir, NULL);
ac3a84
 
ac3a84
@@ -1392,7 +1392,7 @@ int portable_attach(
ac3a84
                 r = attach_unit_file(&paths, image->path, image->type, extension_images,
ac3a84
                                      item, profile, flags, changes, n_changes);
ac3a84
                 if (r < 0)
ac3a84
-                        return r;
ac3a84
+                        return sd_bus_error_set_errnof(error, r, "Failed to attach unit '%s': %m", item->name);
ac3a84
         }
ac3a84
 
ac3a84
         /* We don't care too much for the image symlink, it's just a convenience thing, it's not necessary for proper