yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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