From: Karel Zak Date: Tue, 28 Jan 2025 12:23:15 +0000 (+0100) Subject: libmount: improve error messages in ID-mapping hook X-Git-Tag: v2.42-start~64^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1760fd11641bc60d1a0f62583c9e5b63ddd7d8f2;p=thirdparty%2Futil-linux.git 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 --- 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)