From patchwork Fri Oct 2 13:00:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 54431 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id B542D23009 for ; Fri, 2 Oct 2015 13:46:56 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf16791837lbb.3 for ; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=RUKocgRp5bEwYGRIL0/rmHWuRUPf89oVFwxqh5jpbxg=; b=BGQh1sDVnwx/uOcY69QHZcxXcztOiLGIArVgubDXy5H9KurP0uNIl6+403Y45U1sm2 GVhALS6T6L2cvV1xkwNeeeZgeW3qpC4LDhzC5MY3QEJ9LfD7ZgGHWhtjG+pTzxzkRWyU Yq07a2bR+RcpqSHCXd/4s2L2ZiCAQ9fBMMCMhkjOkFR8eNfqJG1md8NkQFxK/eB5eJqj Nu2sI/2FkkRNq24xuM3C8bLRhMIuJ6VEwmWf2w79d297AnikswuPpwibGrYTTfCdMBYW SStY6dIcXadBKraqsme/dkUwYRezlL+zjkh2WzLzkQjdUn3AIRqsP9O7mWOXoXJsqnN+ fEqg== X-Gm-Message-State: ALoCoQlDasHIIM7YsGISOLOc0xZXDjs7tlwOMDMPiNSW9TBvQSbMJs01+eeKqYMU5qddFpkE/czR X-Received: by 10.112.190.65 with SMTP id go1mr2669710lbc.9.1443793615330; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.38.206 with SMTP id m197ls226252lfm.55.gmail; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) X-Received: by 10.25.150.83 with SMTP id y80mr3575533lfd.119.1443793615181; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id d9si6288312lfg.129.2015.10.02.06.46.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 06:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbos8 with SMTP id s8so26709643lbo.0 for ; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) X-Received: by 10.112.202.35 with SMTP id kf3mr5657316lbc.19.1443793615069; Fri, 02 Oct 2015 06:46:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1256175lbq; Fri, 2 Oct 2015 06:46:53 -0700 (PDT) X-Received: by 10.140.19.175 with SMTP id 44mr19549527qgh.50.1443793612390; Fri, 02 Oct 2015 06:46:52 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q11si10316615qha.87.2015.10.02.06.46.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 Oct 2015 06:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:59884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi0fj-0004K7-Jm for patch@linaro.org; Fri, 02 Oct 2015 09:46:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzxe-0005GT-2Y for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhzxZ-0000Zo-Qz for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:17 -0400 Received: from mail-la0-f45.google.com ([209.85.215.45]:36432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhzxZ-0000ZZ-Kk for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:01:13 -0400 Received: by laclj5 with SMTP id lj5so92035641lac.3 for ; Fri, 02 Oct 2015 06:01:13 -0700 (PDT) X-Received: by 10.112.13.136 with SMTP id h8mr5396885lbc.23.1443790872817; Fri, 02 Oct 2015 06:01:12 -0700 (PDT) Received: from localhost.localdomain (91-157-196-38.elisa-laajakaista.fi. [91.157.196.38]) by smtp.gmail.com with ESMTPSA id w143sm1514751lfd.2.2015.10.02.06.01.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Oct 2015 06:01:11 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 16:00:55 +0300 Message-Id: <138940bf08df1d8e9b862ad019a0d7d451e2413a.1443790691.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.45 Cc: Meador Inge Subject: [Qemu-devel] [PULL 03/13] linux-user: Add proper error messages for bad options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 Signed-off-by: Riku Voipio --- 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 58d8d8d..31aa4d9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4029,7 +4029,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++; @@ -4042,12 +4044,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];