From patchwork Mon Jan 30 11:55:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nir Soffer X-Patchwork-Id: 9544999 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 B347160417 for ; Mon, 30 Jan 2017 12:02:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9566726E47 for ; Mon, 30 Jan 2017 12:02:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 882FC26E73; Mon, 30 Jan 2017 12:02:12 +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 18F8A26E47 for ; Mon, 30 Jan 2017 12:02:11 +0000 (UTC) Received: from localhost ([::1]:59822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYAew-00083X-AJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 30 Jan 2017 07:02:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYAeY-00083E-FY for qemu-devel@nongnu.org; Mon, 30 Jan 2017 07:01:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYAeS-0004xN-RF for qemu-devel@nongnu.org; Mon, 30 Jan 2017 07:01:46 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35255) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cYAeS-0004vR-Kj; Mon, 30 Jan 2017 07:01:40 -0500 Received: by mail-wm0-x241.google.com with SMTP id u63so8429687wmu.2; Mon, 30 Jan 2017 04:01:38 -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=d0n13WbtOd5QyeNONNMP92hg/Uz7oUKO5b4diAltXO2nurtBlhaDEUtq4+DME8gIDW 907AYs29oL9OngOutVEaqApij4u5RM3I2mtX81NPzxm1xTxjehHeGSVeM7VLxDZdt+kr BbSLkQndInXfHOH608YUi+v0qEfgTq76beboLQ8Ml/DyTiTYVpMDiDd1klaWPOIwHVXy Aw4+7OhxdHR4JJnlwQQx6mNHQSwhgPdLFoIt47XQ2hh/YG1Uhz9C8YitqZ5GGmIshh79 nihH5yr0d/yE0rln4XUd6/CTElzO9dOdZps6mIe95EpuyB9l+kr528tNFFQF4GLN7PHZ JjCw== 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=kCro7tCU6t9U+5SlHdBYJ/dJUmisuHx72oYw2LD/j9p8ybz1w4P8Yo+TdQMuRCAf4s /La4fEgej6cIBw3FDZx8lZTYnAzF8dng3kyl2NjHZ/hHeirKUHA3MjmW8S2HeObqv8fW iiQRTsgiZUvAKbAd6uXMQxJGCCkv0kLw6Y8nj+Lf4fyBYxqqm6s0eMrWIl4nCdrQDUw5 JncsJnJywYOZmFhR4LjSi1nT/bHaBHztJdxC/SJnYKb1i0kes29r9oONfHiAJ0NtFpfV FyQGdcqBZd/2a6pa4PjsiuBTUzNghhfW0PUlIQRABsdqWcUY3y8A+GB6OpnKWo8u7Z4v joEQ== X-Gm-Message-State: AIkVDXKpI8EfAjJPyNBYq8OdEKjr7XH1z51gQQ/aztyvTSahFdOwZSSnrrC7hctesdtNxQ== X-Received: by 10.28.44.66 with SMTP id s63mr12840435wms.77.1485777697900; Mon, 30 Jan 2017 04:01:37 -0800 (PST) Received: from lean.com (bzq-82-81-161-50.red.bezeqint.net. [82.81.161.50]) by smtp.gmail.com with ESMTPSA id w70sm22352738wrc.47.2017.01.30.04.01.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 04:01:37 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Mon, 30 Jan 2017 13:55:49 +0200 Message-Id: <20170130115551.27254-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::241 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: kwolf@redhat.com, Nir Soffer , Nir Soffer , qemu-block@nongnu.org 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();