From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXIpn-0006Sp-DI for qemu-devel@nongnu.org; Fri, 27 Jan 2017 21:33:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXIpk-0007ST-By for qemu-devel@nongnu.org; Fri, 27 Jan 2017 21:33:47 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33805) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXIpk-0007SH-4X for qemu-devel@nongnu.org; Fri, 27 Jan 2017 21:33:44 -0500 Received: by mail-wm0-x241.google.com with SMTP id c85so62072522wmi.1 for ; Fri, 27 Jan 2017 18:33:44 -0800 (PST) From: Nir Soffer Date: Sat, 28 Jan 2017 04:33:05 +0200 Message-Id: <20170128023306.22011-1-nirsof@gmail.com> Subject: [Qemu-devel] [PATCH v2 1/2] 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: Kevin Wolf , 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 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 v1: - Improve commit message - Add regression tests 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