Update such that "cryptomount -u UUID" will not print two error messages when an invalid passphrase is given and the most relevant error message will be displayed.
Improve error message which is displayed when a UUID is specified, but no cryptodisk backends find a disk with that UUID. Also, make cryptomount return failure when no cryptodisk modules are loaded, which allows an error to be displayed notifying the user that they'll want to load a backend module to make cryptomount useful. Signed-off-by: Glenn Washburn <developm...@efficientek.com> --- grub-core/disk/cryptodisk.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 9224105ac..aa086837d 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -1100,11 +1100,15 @@ grub_cryptodisk_scan_device (const char *name, grub_disk_close (source); - /* - * Do not print error when err is GRUB_ERR_BAD_MODULE to avoid many unhelpful - * error messages. - */ - if (err != GRUB_ERR_NONE && err != GRUB_ERR_EXISTS && err != GRUB_ERR_BAD_MODULE) + if (err == GRUB_ERR_NONE || err == GRUB_ERR_EXISTS) + ; /* Success, skip the error handling */ + else if (err == GRUB_ERR_BAD_MODULE) + /* Do nothing to avoid printing unhelpful error messages */ + grub_errno = GRUB_ERR_NONE; + else if (cargs->search_uuid != NULL) + /* Push error onto stack to save for cryptomount */ + grub_error_push(); + else grub_print_error (); return (err == GRUB_ERR_NONE && search_uuid != NULL); } @@ -1117,6 +1121,9 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) if (argc < 1 && !state[1].set && !state[2].set) return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); + if (grub_cryptodisk_list == NULL) + return grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk modules loaded"); + if (state[0].set) { int found_uuid; @@ -1135,9 +1142,19 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) found_uuid = grub_device_iterate (&grub_cryptodisk_scan_device, NULL); search_uuid = NULL; - if (!found_uuid) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found"); - return GRUB_ERR_NONE; + if (found_uuid) + return GRUB_ERR_NONE; + else if (grub_errno == GRUB_ERR_NONE) + { + /* + * Try to pop the next error on the stack. If there is not one, then + * no device matched the given UUID. + */ + grub_error_pop(); + if (grub_errno == GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found, perhaps a needed disk or cryptodisk module is not loaded"); + } + return grub_errno; } else if (state[1].set || (argc == 0 && state[2].set)) { -- 2.27.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel