]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: event: Introduce virshEventPrintf
authorPeter Krempa <pkrempa@redhat.com>
Thu, 13 Apr 2023 07:31:34 +0000 (09:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Apr 2023 13:22:02 +0000 (15:22 +0200)
Extract internals of virshEventPrint into a function that can take the
format string. The function will be used in upcoming patches which make
the event formatting translatable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-domain-event.c

index 1ed204fa9a09c90b62c239e63bc449aa45134590..a8a321590c42a4f0a8d0866797090cb670dec910 100644 (file)
@@ -286,6 +286,33 @@ struct virshDomEventData {
 };
 typedef struct virshDomEventData virshDomEventData;
 
+
+static void G_GNUC_PRINTF(2, 3)
+virshEventPrintf(virshDomEventData *data,
+                 const char *fmt,
+                 ...)
+{
+    va_list ap;
+
+    if (!data->loop && *data->count)
+        return;
+
+    if (data->timestamp) {
+        char timestamp[VIR_TIME_STRING_BUFLEN] = "";
+
+        ignore_value(virTimeStringNowRaw(timestamp));
+        vshPrint(data->ctl, "%s: ", timestamp);
+    }
+
+    va_start(ap, fmt);
+    vshPrintVa(data->ctl, fmt, ap);
+    va_end(ap);
+
+    (*data->count)++;
+    if (!data->loop)
+        vshEventDone(data->ctl);
+}
+
 /**
  * virshEventPrint:
  *
@@ -305,25 +332,10 @@ virshEventPrint(virshDomEventData *data,
     if (!(msg = virBufferContentAndReset(buf)))
         return;
 
-    if (!data->loop && *data->count)
-        return;
-
-    if (data->timestamp) {
-        char timestamp[VIR_TIME_STRING_BUFLEN];
-
-        if (virTimeStringNowRaw(timestamp) < 0)
-            timestamp[0] = '\0';
-
-        vshPrint(data->ctl, "%s: %s", timestamp, msg);
-    } else {
-        vshPrint(data->ctl, "%s", msg);
-    }
-
-    (*data->count)++;
-    if (!data->loop)
-        vshEventDone(data->ctl);
+    virshEventPrintf(data, "%s", msg);
 }
 
+
 static void
 virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED,
                        virDomainPtr dom,