mirror of https://github.com/xemu-project/xemu.git
qemu-io: Exit with error when a command failed
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 <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20180509194302.21585-4-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
b32d7a39af
commit
6b3aa8485c
28
qemu-io.c
28
qemu-io.c
|
@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque)
|
||||||
*fetchable= 1;
|
*fetchable= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void command_loop(void)
|
static int command_loop(void)
|
||||||
{
|
{
|
||||||
int i, fetchable = 0, prompted = 0;
|
int i, fetchable = 0, prompted = 0;
|
||||||
|
int ret, last_error = 0;
|
||||||
char *input;
|
char *input;
|
||||||
|
|
||||||
for (i = 0; !quit_qemu_io && i < ncmdline; i++) {
|
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) {
|
if (cmdline) {
|
||||||
g_free(cmdline);
|
g_free(cmdline);
|
||||||
return;
|
return last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!quit_qemu_io) {
|
while (!quit_qemu_io) {
|
||||||
|
@ -431,13 +435,19 @@ static void command_loop(void)
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qemuio_command(qemuio_blk, input);
|
ret = qemuio_command(qemuio_blk, input);
|
||||||
g_free(input);
|
g_free(input);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
last_error = ret;
|
||||||
|
}
|
||||||
|
|
||||||
prompted = 0;
|
prompted = 0;
|
||||||
fetchable = 0;
|
fetchable = 0;
|
||||||
}
|
}
|
||||||
qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
|
qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
return last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_user_command(char *optarg)
|
static void add_user_command(char *optarg)
|
||||||
|
@ -502,6 +512,7 @@ int main(int argc, char **argv)
|
||||||
int c;
|
int c;
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
int flags = BDRV_O_UNMAP;
|
int flags = BDRV_O_UNMAP;
|
||||||
|
int ret;
|
||||||
bool writethrough = true;
|
bool writethrough = true;
|
||||||
Error *local_error = NULL;
|
Error *local_error = NULL;
|
||||||
QDict *opts = 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.
|
* Make sure all outstanding requests complete before the program exits.
|
||||||
|
@ -672,5 +683,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
blk_unref(qemuio_blk);
|
blk_unref(qemuio_blk);
|
||||||
g_free(readline_state);
|
g_free(readline_state);
|
||||||
return 0;
|
|
||||||
|
if (ret < 0) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue