From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Nir Soffer Date: Mon, 30 Jan 2017 13:55:49 +0200 Message-Id: <20170130115551.27254-1-nirsof@gmail.com> Subject: [Qemu-devel] [PATCH v3 1/3] 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: kwolf@redhat.com, qemu-block@nongnu.org, 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 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(); -- 2.9.3