From 1760fd11641bc60d1a0f62583c9e5b63ddd7d8f2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 28 Jan 2025 13:23:15 +0100 Subject: [PATCH] libmount: improve error messages in ID-mapping hook * 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 --- libmount/src/hook_idmap.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libmount/src/hook_idmap.c b/libmount/src/hook_idmap.c index 4592f5ef6..e8c4cab5a 100644 --- a/libmount/src/hook_idmap.c +++ b/libmount/src/hook_idmap.c @@ -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) -- 2.47.3