From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCAkF-0006se-7H for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:03:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCAkA-0003MA-My for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:03:55 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:58011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCAkA-0003Kz-Hs for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:03:50 -0400 From: Date: Mon, 6 Jul 2015 11:03:40 -0700 Message-ID: <1436205821-20320-4-git-send-email-meadori@codesourcery.com> In-Reply-To: <1436205821-20320-1-git-send-email-meadori@codesourcery.com> References: <1436205821-20320-1-git-send-email-meadori@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: riku.voipio@iki.fi, Meador Inge From: Meador Inge This patch adds better support for diagnosing option parser errors. The previous implementation just printed the usage text and exited when a bad option or argument was found. This made it very difficult to determine why the usage was being displayed and it was doubly confusing for cases like '--help' (it wasn't clear that --help was actually an error). Signed-off-by: Meador Inge --- linux-user/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 2922d23..94badfc 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3806,7 +3806,9 @@ static int parse_args(int argc, char **argv) if (!strcmp(r, arginfo->argv)) { if (arginfo->has_arg) { if (optind >= argc) { - usage(1); + (void) fprintf(stderr, + "qemu: missing argument for option '%s'\n", r); + exit(1); } arginfo->handle_opt(argv[optind]); optind++; @@ -3819,12 +3821,14 @@ static int parse_args(int argc, char **argv) /* no option matched the current argv */ if (arginfo->handle_opt == NULL) { - usage(1); + (void) fprintf(stderr, "qemu: unknown option '%s'\n", r); + exit(1); } } if (optind >= argc) { - usage(1); + (void) fprintf(stderr, "qemu: no user program specified\n"); + exit(1); } filename = argv[optind]; -- 1.8.1.1