]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: qemucapsprobemock: Simplify and extract skipping of empty lines
authorPeter Krempa <pkrempa@redhat.com>
Thu, 3 May 2018 15:34:43 +0000 (17:34 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Jun 2018 08:27:50 +0000 (10:27 +0200)
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@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
tests/qemucapsprobemock.c

index 97497eb438f2bfedcd9b08b3772e9d3df91e7eff..f26fa6b2850424b039dc6944b5fa64433aa42e0d 100644 (file)
     } 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: