[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 15/29] qemu-io: Exit with error when a command failed
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 15/29] qemu-io: Exit with error when a command failed |
Date: |
Mon, 11 Jun 2018 16:25:57 +0200 |
Currently, qemu-io basically always returns success when it gets to
interactive mode (so once the whole command line has been parsed; even
before the commands on the command line are interpreted). That is not
very useful.
This patch makes qemu-io return failure when any of the executed
commands failed.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1519617
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
qemu-io.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index ec6683803f..13829f5e21 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque)
*fetchable= 1;
}
-static void command_loop(void)
+static int command_loop(void)
{
int i, fetchable = 0, prompted = 0;
+ int ret, last_error = 0;
char *input;
for (i = 0; !quit_qemu_io && i < ncmdline; i++) {
- qemuio_command(qemuio_blk, cmdline[i]);
+ ret = qemuio_command(qemuio_blk, cmdline[i]);
+ if (ret < 0) {
+ last_error = ret;
+ }
}
if (cmdline) {
g_free(cmdline);
- return;
+ return last_error;
}
while (!quit_qemu_io) {
@@ -431,13 +435,19 @@ static void command_loop(void)
if (input == NULL) {
break;
}
- qemuio_command(qemuio_blk, input);
+ ret = qemuio_command(qemuio_blk, input);
g_free(input);
+ if (ret < 0) {
+ last_error = ret;
+ }
+
prompted = 0;
fetchable = 0;
}
qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
+
+ return last_error;
}
static void add_user_command(char *optarg)
@@ -502,6 +512,7 @@ int main(int argc, char **argv)
int c;
int opt_index = 0;
int flags = BDRV_O_UNMAP;
+ int ret;
bool writethrough = true;
Error *local_error = NULL;
QDict *opts = NULL;
@@ -663,7 +674,7 @@ int main(int argc, char **argv)
}
}
}
- command_loop();
+ ret = command_loop();
/*
* Make sure all outstanding requests complete before the program exits.
@@ -672,5 +683,10 @@ int main(int argc, char **argv)
blk_unref(qemuio_blk);
g_free(readline_state);
- return 0;
+
+ if (ret < 0) {
+ return 1;
+ } else {
+ return 0;
+ }
}
--
2.17.1
- [Qemu-block] [PULL 04/29] qemu-img: Amendment support implies create_opts, (continued)
- [Qemu-block] [PULL 04/29] qemu-img: Amendment support implies create_opts, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 03/29] iotests: Add creation test to 153, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 07/29] qemu-img: Add print_amend_option_help(), Max Reitz, 2018/06/11
- [Qemu-block] [PULL 05/29] block: Add Error parameter to bdrv_amend_options, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 06/29] qemu-option: Pull out "Supported options" print, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 09/29] iotests: Test help option for unsupporting formats, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 10/29] iotests: Rework 113, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 11/29] qcow2: Repair OFLAG_COPIED when fixing leaks, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 08/29] qemu-img: Recognize no creation support in -o help, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 12/29] iotests: Repairing error during snapshot deletion, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 15/29] qemu-io: Exit with error when a command failed,
Max Reitz <=
- [Qemu-block] [PULL 17/29] iotests: Let 216 make use of qemu-io's exit code, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 16/29] iotests.py: Add qemu_io_silent, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 18/29] qemu-img: Resolve relative backing paths in rebase, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 14/29] qemu-io: Let command functions return error code, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 13/29] qemu-io: Drop command functions' return values, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 20/29] qemu-img: Special post-backing convert handling, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 19/29] iotests: Add test for rebasing with relative paths, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 21/29] iotests: Test post-backing convert target behavior, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 22/29] iotests: improve pause_job, Max Reitz, 2018/06/11
- [Qemu-block] [PULL 23/29] iotests: Fix 219's timing, Max Reitz, 2018/06/11