All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nir Soffer <nirsof@gmail.com>
To: qemu-devel@nongnu.org
Cc: Nir Soffer <nsoffer@redhat.com>, Nir Soffer <nirsof@gmail.com>
Subject: [Qemu-devel] [PATCH] qemu-io: Return non-zero exit code on failure
Date: Wed, 11 Jan 2017 20:24:55 +0200	[thread overview]
Message-ID: <20170111182455.15160-1-nirsof@gmail.com> (raw)

From: Nir Soffer <nsoffer@redhat.com>

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 <nirsof@gmail.com>
---
 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

             reply	other threads:[~2017-01-11 18:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 18:24 Nir Soffer [this message]
2017-01-11 21:51 ` [Qemu-devel] [PATCH] qemu-io: Return non-zero exit code on failure Eric Blake
2017-01-12  3:01   ` Fam Zheng
2017-01-12 20:04     ` Nir Soffer
2017-01-12 19:56   ` Nir Soffer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170111182455.15160-1-nirsof@gmail.com \
    --to=nirsof@gmail.com \
    --cc=nsoffer@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.