From patchwork Sat Jan 28 03:59:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nir Soffer X-Patchwork-Id: 9543017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0444560429 for ; Sat, 28 Jan 2017 04:00:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8BC727AB2 for ; Sat, 28 Jan 2017 04:00:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBFB226E69; Sat, 28 Jan 2017 04:00:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6281726E69 for ; Sat, 28 Jan 2017 04:00:51 +0000 (UTC) Received: from localhost ([::1]:49843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXKC0-0004XF-UM for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 Jan 2017 23:00:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXKBd-0004X9-SW for qemu-devel@nongnu.org; Fri, 27 Jan 2017 23:00:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXKBa-0000Ai-Qe for qemu-devel@nongnu.org; Fri, 27 Jan 2017 23:00:25 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36582) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXKBa-0000Ac-K2 for qemu-devel@nongnu.org; Fri, 27 Jan 2017 23:00:22 -0500 Received: by mail-wm0-x244.google.com with SMTP id r126so62456702wmr.3 for ; Fri, 27 Jan 2017 20:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wvx+gUC6VLWKzn7Lm88Ogtq8o+EphgaXC8upSNckxC4=; b=CAuqPOEvTMLxLBX67z+S7XUg3dh7pHyJAzOWuzwk8gl/EE/IedeL6NW2xE8/n5nf4C qWwjTzkCqUC2upamuwLCJG1qDvYh3H/V+SqSZoebtFs5E5eAzJeBBdXCphsfnxkn1BIv BXug73iHrEv3uVt7yiqsDsUq3twKF1R8Gjmk1oPUrdoH1LTCYUe5/pmZnOYqurvm6Jgb cPML4rxMTKeQHAtszLUygozLshzYJH5cjnE33F3O2+BLXVnKRCmxnbVgOdflSH85Lj+4 kGO5hngeSrE+pWrDyDuvBwKo+QuaF/GiphaSJzbZ2ybr7EW1EZQFme6rghYRwR8lMNOS /zbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wvx+gUC6VLWKzn7Lm88Ogtq8o+EphgaXC8upSNckxC4=; b=l0goN10MQd0VTsoYTfGwb5HXvJzI/wXzYWqca9CFFLEFOYTkC84hV2LqirIzkkJF2n 30g8n3/BmUG0FSumFf3HCrmoKPdWiWRtKnLusv3DuAoJ03dyuVjM8/pxhOCM8MXQeZjw YyIpzbJaJAK2T+Yr5iZFs+j3Fd4MBtErlAEF2r7G3sZ59/1FpgpKvQu/04PxqV1WYpUY HMDjMPN1QZGHf6Dq1Tjt8k49KCjIc2eu3FYtYSyq4oc4K5Hz4NfZtgU2HSnJchGGrWAi mhLeYfYflSdi2J/avt0X76MZXFnVqajrzbD4Iz10+bTbLRunTEzAaF3hO12mIYGaIZ+n MPYg== X-Gm-Message-State: AIkVDXKv6uADag1AZqEdSI7rE+KLV7gvStK+qgkGMC+cw0/spqtEXQP7b262UBF5HnkFoQ== X-Received: by 10.223.150.84 with SMTP id c20mr10002349wra.178.1485576021379; Fri, 27 Jan 2017 20:00:21 -0800 (PST) Received: from lean.local (bzq-79-181-80-51.red.bezeqint.net. [79.181.80.51]) by smtp.gmail.com with ESMTPSA id c132sm6826361wme.21.2017.01.27.20.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jan 2017 20:00:20 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Sat, 28 Jan 2017 05:59:27 +0200 Message-Id: <20170128035929.10168-1-nirsof@gmail.com> X-Mailer: git-send-email 2.9.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH v3 1/3] qemu-io: Return non-zero exit code on failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Nir Soffer , Nir Soffer Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Nir Soffer The result of openfile was not checked, leading to failure deep in the actual command with confusing error message, and exiting with exit code 0. Here is a simple example - trying to read with the wrong format: $ touch file $ qemu-io -f qcow2 -c 'read -P 1 0 1024' file; echo $? can't open device file: Image is not in qcow2 format no file open, try 'help open' 0 With this patch, we fail earlier with exit code 1: $ ./qemu-io -f qcow2 -c 'read -P 1 0 1024' file; echo $? can't open device file: Image is not in qcow2 format 1 Signed-off-by: Nir Soffer Reviewed-by: Eric Blake Reviewed-by: Fam Zheng --- Changes since v2: - Adding missing signed-off-by - Fix tests expecting the wrong output qemu-io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 23a229f..427cbae 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -595,13 +595,17 @@ int main(int argc, char **argv) exit(1); } opts = qemu_opts_to_qdict(qopts, NULL); - openfile(NULL, flags, writethrough, opts); + if (openfile(NULL, flags, writethrough, opts)) { + exit(1); + } } else { if (format) { opts = qdict_new(); qdict_put(opts, "driver", qstring_from_str(format)); } - openfile(argv[optind], flags, writethrough, opts); + if (openfile(argv[optind], flags, writethrough, opts)) { + exit(1); + } } } command_loop();