|
|
ae23c9 |
From c9498bf0eae922fb4673d024904a8d93bdf35d2d Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Date: Mon, 18 Jun 2018 16:43:10 +0200
|
|
|
ae23c9 |
Subject: [PATCH 051/268] qemu-io: Exit with error when a command failed
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Message-id: <20180618164312.24423-4-mreitz@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 80780
|
|
|
ae23c9 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/5] qemu-io: Exit with error when a command failed
|
|
|
ae23c9 |
Bugzilla: 1519617
|
|
|
ae23c9 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Currently, qemu-io basically always returns success when it gets to
|
|
|
ae23c9 |
interactive mode (so once the whole command line has been parsed; even
|
|
|
ae23c9 |
before the commands on the command line are interpreted). That is not
|
|
|
ae23c9 |
very useful.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
This patch makes qemu-io return failure when any of the executed
|
|
|
ae23c9 |
commands failed.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1519617
|
|
|
ae23c9 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
ae23c9 |
Message-id: 20180509194302.21585-4-mreitz@redhat.com
|
|
|
ae23c9 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit 6b3aa8485ca8e61b168f51d465188855cf549bd2)
|
|
|
ae23c9 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
qemu-io.c | 28 ++++++++++++++++++++++------
|
|
|
ae23c9 |
1 file changed, 22 insertions(+), 6 deletions(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/qemu-io.c b/qemu-io.c
|
|
|
ae23c9 |
index ec66838..13829f5 100644
|
|
|
ae23c9 |
--- a/qemu-io.c
|
|
|
ae23c9 |
+++ b/qemu-io.c
|
|
|
ae23c9 |
@@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque)
|
|
|
ae23c9 |
*fetchable= 1;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-static void command_loop(void)
|
|
|
ae23c9 |
+static int command_loop(void)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
int i, fetchable = 0, prompted = 0;
|
|
|
ae23c9 |
+ int ret, last_error = 0;
|
|
|
ae23c9 |
char *input;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
for (i = 0; !quit_qemu_io && i < ncmdline; i++) {
|
|
|
ae23c9 |
- qemuio_command(qemuio_blk, cmdline[i]);
|
|
|
ae23c9 |
+ ret = qemuio_command(qemuio_blk, cmdline[i]);
|
|
|
ae23c9 |
+ if (ret < 0) {
|
|
|
ae23c9 |
+ last_error = ret;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
if (cmdline) {
|
|
|
ae23c9 |
g_free(cmdline);
|
|
|
ae23c9 |
- return;
|
|
|
ae23c9 |
+ return last_error;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
while (!quit_qemu_io) {
|
|
|
ae23c9 |
@@ -431,13 +435,19 @@ static void command_loop(void)
|
|
|
ae23c9 |
if (input == NULL) {
|
|
|
ae23c9 |
break;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
- qemuio_command(qemuio_blk, input);
|
|
|
ae23c9 |
+ ret = qemuio_command(qemuio_blk, input);
|
|
|
ae23c9 |
g_free(input);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+ if (ret < 0) {
|
|
|
ae23c9 |
+ last_error = ret;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
prompted = 0;
|
|
|
ae23c9 |
fetchable = 0;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ return last_error;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
static void add_user_command(char *optarg)
|
|
|
ae23c9 |
@@ -502,6 +512,7 @@ int main(int argc, char **argv)
|
|
|
ae23c9 |
int c;
|
|
|
ae23c9 |
int opt_index = 0;
|
|
|
ae23c9 |
int flags = BDRV_O_UNMAP;
|
|
|
ae23c9 |
+ int ret;
|
|
|
ae23c9 |
bool writethrough = true;
|
|
|
ae23c9 |
Error *local_error = NULL;
|
|
|
ae23c9 |
QDict *opts = NULL;
|
|
|
ae23c9 |
@@ -663,7 +674,7 @@ int main(int argc, char **argv)
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
- command_loop();
|
|
|
ae23c9 |
+ ret = command_loop();
|
|
|
ae23c9 |
|
|
|
ae23c9 |
/*
|
|
|
ae23c9 |
* Make sure all outstanding requests complete before the program exits.
|
|
|
ae23c9 |
@@ -672,5 +683,10 @@ int main(int argc, char **argv)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
blk_unref(qemuio_blk);
|
|
|
ae23c9 |
g_free(readline_state);
|
|
|
ae23c9 |
- return 0;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (ret < 0) {
|
|
|
ae23c9 |
+ return 1;
|
|
|
ae23c9 |
+ } else {
|
|
|
ae23c9 |
+ return 0;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|