Sfoglia il codice sorgente

libdpkg: Use fully buffered output on non-tty

If stdout is not a tty, we don't need immediate feedback, and not
buffering it can cause a significant slow down in case the amount
printed each time is very small.

Reported-by: Shawn Landden <shawnlandden@gmail.com>
Guillem Jover 13 anni fa
parent
commit
50c1cb4d6e
2 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 2 0
      debian/changelog
  2. 5 1
      lib/dpkg/report.c

+ 2 - 0
debian/changelog

@@ -40,6 +40,8 @@ dpkg (1.17.2) UNRELEASED; urgency=low
   * Fix «dpkg-query --list» output when using multibyte character strings,
     to avoid unaligned columns and mojibake. Closes: #257505, #718541
     Based on a patch by Changwoo Ryu <cwryu@debian.org>.
+  * Use fully buffered output on non-tty stdout.
+    Reported by Shawn Landden <shawnlandden@gmail.com>.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 5 - 1
lib/dpkg/report.c

@@ -24,6 +24,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include <dpkg/macros.h>
 #include <dpkg/i18n.h>
@@ -33,7 +34,10 @@
 void
 dpkg_set_report_buffer(FILE *fp)
 {
-	setvbuf(fp, NULL, _IONBF, 0);
+	if (isatty(STDOUT_FILENO))
+		setvbuf(fp, NULL, _IONBF, 0);
+	else
+		setvbuf(fp, NULL, _IOFBF, 0);
 }
 
 static int warn_count = 0;