From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRNaS-00069w-V2 for qemu-devel@nongnu.org; Wed, 11 Jan 2017 13:25:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRNaP-0006Dt-SN for qemu-devel@nongnu.org; Wed, 11 Jan 2017 13:25:28 -0500 Received: from mail-wj0-x241.google.com ([2a00:1450:400c:c01::241]:36078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRNaP-0006By-Is for qemu-devel@nongnu.org; Wed, 11 Jan 2017 13:25:25 -0500 Received: by mail-wj0-x241.google.com with SMTP id dh1so11526765wjb.3 for ; Wed, 11 Jan 2017 10:25:25 -0800 (PST) From: Nir Soffer Date: Wed, 11 Jan 2017 20:24:55 +0200 Message-Id: <20170111182455.15160-1-nirsof@gmail.com> Subject: [Qemu-devel] [PATCH] qemu-io: Return non-zero exit code on failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Nir Soffer , Nir Soffer 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 one example - trying to read a pattern from an invalid chain: $ qemu-io -c 'read -P 1 0 1024' top.qcow2; echo $? can't open device top.qcow2: Could not open backing 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 -c 'read -P 1 0 1024' top.qcow2; echo $? can't open device top.qcow2: Could not open backing file: Image is not in qcow2 format 1 Signed-off-by: Nir Soffer --- 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(); -- 2.9.3