]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshPrintJobProgress: Don't rewrite migration status line on non-terminals
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Jun 2025 08:00:20 +0000 (10:00 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 18 Jun 2025 10:14:31 +0000 (12:14 +0200)
On non-terminals print each progress report on a new line. Fix based on
suggestion in the issue report.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/756
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 8d615b6e7aa2899975e614f250e80c6c00003eb5..7253596f4ac8ac95f398554055995b46dddefdef 100644 (file)
@@ -2091,10 +2091,13 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
 
 
 static void
-virshPrintJobProgress(const char *label, unsigned long long remaining,
+virshPrintJobProgress(const char *label,
+                      unsigned long long remaining,
                       unsigned long long total)
 {
     double progress = 100.00;
+    const char *term_start = "\r";
+    const char *term_end = "";
 
     /* if remaining == 0 migration has completed */
     if (remaining != 0) {
@@ -2106,10 +2109,16 @@ virshPrintJobProgress(const char *label, unsigned long long remaining,
         }
     }
 
+    if (!isatty(STDERR_FILENO)) {
+        term_start = "";
+        term_end = "\n";
+    }
+
     /* see comments in vshError about why we must flush */
     fflush(stdout);
     /* avoid auto-round-off of double by keeping only 2 decimals */
-    fprintf(stderr, "\r%s: [%5.2f %%]", label, (int)(progress*100)/100.0);
+    fprintf(stderr, "%s%s: [%5.2f %%]%s",
+            term_start, label, (int)(progress*100)/100.0, term_end);
     fflush(stderr);
 }