Blame SOURCES/kvm-qemu-io-Exit-with-error-when-a-command-failed.patch

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