git: 6fdb07d5b7e9 - main - loader: provide error message in command_errmsg instead of printing
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 21 Sep 2024 11:26:26 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=6fdb07d5b7e9293a6851a23b7ecb26636cf1ec1e commit 6fdb07d5b7e9293a6851a23b7ecb26636cf1ec1e Author: Ahmad Khalifa <ahmadkhalifa570@gmail.com> AuthorDate: 2024-08-12 12:11:06 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-09-21 11:25:16 +0000 loader: provide error message in command_errmsg instead of printing Also provide an error message when argc is too long instead of printing "no error message". Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1381 --- stand/efi/loader/copy.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/stand/efi/loader/copy.c b/stand/efi/loader/copy.c index 3e466e875af8..90a55089ffc4 100644 --- a/stand/efi/loader/copy.c +++ b/stand/efi/loader/copy.c @@ -223,7 +223,7 @@ command_copy_staging(int argc, char *argv[]) int prev; if (argc > 2) { - return (CMD_ERROR); + goto usage; } else if (argc == 2) { prev = copy_staging; if (strcmp(argv[1], "enable") == 0) @@ -232,10 +232,8 @@ command_copy_staging(int argc, char *argv[]) copy_staging = COPY_STAGING_DISABLE; else if (strcmp(argv[1], "auto") == 0) copy_staging = COPY_STAGING_AUTO; - else { - printf("usage: copy_staging enable|disable|auto\n"); - return (CMD_ERROR); - } + else + goto usage; if (prev != copy_staging) { printf("changed copy_staging, unloading kernel\n"); unload(); @@ -246,6 +244,10 @@ command_copy_staging(int argc, char *argv[]) printf("copy staging: %s\n", mode[copy_staging]); } return (CMD_OK); + +usage: + command_errmsg = "usage: copy_staging enable|disable|auto"; + return (CMD_ERROR); } COMMAND_SET(copy_staging, "copy_staging", "copy staging", command_copy_staging); #endif @@ -257,13 +259,11 @@ command_staging_slop(int argc, char *argv[]) u_long new, prev; if (argc > 2) { - return (CMD_ERROR); + goto err; } else if (argc == 2) { new = strtoul(argv[1], &endp, 0); - if (*endp != '\0') { - printf("invalid slop value\n"); - return (CMD_ERROR); - } + if (*endp != '\0') + goto err; if (staging_slop != new) { staging_slop = new; printf("changed slop, unloading kernel\n"); @@ -276,6 +276,10 @@ command_staging_slop(int argc, char *argv[]) printf("staging slop %#lx\n", staging_slop); } return (CMD_OK); + +err: + command_errmsg = "invalid slop value"; + return (CMD_ERROR); } COMMAND_SET(staging_slop, "staging_slop", "set staging slop", command_staging_slop);