]> xenbits.xensource.com Git - xen.git/commitdiff
tools/livepatch: Set stdout and stderr unbuffered
authorRoss Lagerwall <ross.lagerwall@citrix.com>
Wed, 14 Dec 2016 07:51:54 +0000 (07:51 +0000)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 14 Dec 2016 20:27:19 +0000 (15:27 -0500)
Using both stdout and stderr interleaved without newlines can result in
strange output when using line buffered mode (e.g. a terminal) or when
fully buffered (e.g. redirected to a file). Set stdout to unbuffered mode
to fix this (stderr is always unbuffered by default).

Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
tools/misc/xen-livepatch.c

index f6c7c8a629f4bbcf43990fcabf9f134e51ebed86..56ae5aab1c1fc817c552de9e9b6686675f991579 100644 (file)
@@ -330,7 +330,6 @@ int action_func(int argc, char *argv[], unsigned int idx)
         }
 
         printf(".");
-        fflush(stdout);
         usleep(DELAY);
     } while ( ++retry < RETRIES );
 
@@ -416,6 +415,12 @@ int main(int argc, char *argv[])
 {
     int i, j = 0, ret;
 
+    /*
+     * Set stdout to be unbuffered to avoid having to fflush when
+     * printing without a newline.
+     */
+    setvbuf(stdout, NULL, _IONBF, 0);
+
     if ( argc  <= 1 )
     {
         show_help();