]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Refactor vshError
authorJiri Denemark <jdenemar@redhat.com>
Thu, 20 Feb 2025 12:12:22 +0000 (13:12 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 24 Feb 2025 10:14:11 +0000 (11:14 +0100)
The code is moved into a newly introduced generic vshPrintStderr and
vshError changed into a tiny wrapper.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/vsh.c

index 64507fe5608da1e20c312f03a1144db1e4762889..91e2ae20672d9f0425a962561faa16325f51de55 100644 (file)
@@ -2111,18 +2111,18 @@ vshTTYMakeRaw(vshControl *ctl G_GNUC_UNUSED,
 }
 
 
-void
-vshError(vshControl *ctl, const char *format, ...)
+static void G_GNUC_PRINTF(3, 0)
+vshPrintStderr(vshControl *ctl,
+               int level,
+               const char *format,
+               va_list ap)
 {
-    va_list ap;
     g_autofree char *str = NULL;
 
-    va_start(ap, format);
     str = g_strdup_vprintf(format, ap);
-    va_end(ap);
 
     if (ctl)
-        vshOutputLogFile(ctl, VSH_ERR_ERROR, str);
+        vshOutputLogFile(ctl, level, str);
 
     /* Most output is to stdout, but if someone ran virsh 2>&1, then
      * printing to stderr will not interleave correctly with stdout
@@ -2133,6 +2133,17 @@ vshError(vshControl *ctl, const char *format, ...)
 }
 
 
+void
+vshError(vshControl *ctl, const char *format, ...)
+{
+    va_list ap;
+
+    va_start(ap, format);
+    vshPrintStderr(ctl, VSH_ERR_ERROR, format, ap);
+    va_end(ap);
+}
+
+
 void
 vshEventLoop(void *opaque)
 {