[RFC PATCH 4/9] tests: qemucapsprobemock: Simplify and extract skipping of empty lines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The prettyfied output may sometimes contain empty lines which would
desynchonize the test monitor workers. The skipping code can be much
simplified though. Also a extract it so so that it's obvious what
it's doing and can be reused.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/qemucapsprobemock.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index 97497eb438..f26fa6b285 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -38,6 +38,21 @@
     } while (0)


+static void
+printLineSkipEmpty(const char *line,
+                   FILE *fp)
+{
+    const char *p;
+
+    for (p = line; *p; p++) {
+        if (p[0] == '\n' && p[1] == '\n')
+            continue;
+
+        fputc(*p, fp);
+    }
+}
+
+
 static int (*realQemuMonitorSend)(qemuMonitorPtr mon,
                                   qemuMonitorMessagePtr msg);

@@ -74,8 +89,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
     if (ret == 0 &&
         (value = virJSONValueFromString(line)) &&
         (json = virJSONValueToString(value, 1))) {
-        char *p;
-        bool skip = false;

         if (first) {
             first = false;
@@ -86,14 +99,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
             putchar('\n');
         }

-        for (p = json; *p; p++) {
-            if (skip && *p == '\n') {
-                continue;
-            } else {
-                skip = *p == '\n';
-                putchar(*p);
-            }
-        }
+        printLineSkipEmpty(json, stdout);
     }

  cleanup:
-- 
2.16.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux