]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: improve error messages in ID-mapping hook
authorKarel Zak <kzak@redhat.com>
Tue, 28 Jan 2025 12:23:15 +0000 (13:23 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2025 11:34:41 +0000 (12:34 +0100)
* save failed syscall status
* allow to read messages from kernel
* add proper error messages if kernel is silent

OLD:
  mount: /foo: mount failed: Unknown error 5013.
NEW:
  mount: /foo: mount_setattr() failed: cannot set ID-mapping: Operation not permitted.

Addresses: https://github.com/util-linux/util-linux/issues/3373
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_idmap.c

index 4592f5ef6a18546c8355e9232a7b35bf5467610b..e8c4cab5a06192a6082be9bfaccefa0fa601f410 100644 (file)
@@ -333,6 +333,7 @@ static int hook_mount_post(
                            (recursive ? AT_RECURSIVE : 0));
        if (fd_tree < 0) {
                DBG(HOOK, ul_debugobj(hs, " failed to open tree"));
+               mnt_context_syscall_save_status(cxt, "open_tree", 0);
                return -MNT_ERR_IDMAP;
        }
 
@@ -341,7 +342,11 @@ static int hook_mount_post(
                           AT_EMPTY_PATH | (recursive ? AT_RECURSIVE : 0),
                           &attr, sizeof(attr));
        if (rc < 0) {
-               DBG(HOOK, ul_debugobj(hs, " failed to set attributes"));
+               mnt_context_syscall_save_status(cxt, "mount_setattr", 0);
+               if (!mnt_context_read_mesgs(cxt, fd_tree)) {
+                       /* TRANSLATORS: Don't translate "e ". It's a message classifier. */
+                       mnt_context_sprintf_mesg(cxt, _("e cannot set ID-mapping: %m"));
+               }
                goto done;
        }
 
@@ -351,8 +356,13 @@ static int hook_mount_post(
                umount2(target, MNT_DETACH);
 
                rc = move_mount(fd_tree, "", -1, target, MOVE_MOUNT_F_EMPTY_PATH);
-               if (rc)
-                       DBG(HOOK, ul_debugobj(hs, " failed to set move mount"));
+               if (rc < 0) {
+                       mnt_context_syscall_save_status(cxt, "move_mount", 0);
+                       if (!mnt_context_read_mesgs(cxt, fd_tree)) {
+                               /* TRANSLATORS: Don't translate "e ". It's a message classifier. */
+                               mnt_context_sprintf_mesg(cxt, _("e cannot set ID-mapping: %m"));
+                       }
+               }
        }
 done:
        if (is_private)