]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
qemu-progress.c: printf isn't signal safe
authorJes Sorensen <Jes.Sorensen@redhat.com>
Thu, 28 Apr 2011 11:58:30 +0000 (13:58 +0200)
committerKevin Wolf <kwolf@redhat.com>
Tue, 3 May 2011 09:29:21 +0000 (11:29 +0200)
Change the signal handling to indicate a signal is pending, rather
then printing directly from the signal handler.

In addition make the signal prints go to stderr, rather than stdout.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-progress.c

index e1feb8961479235b433a1afe27f0a20902f94408..a4894c0dfc5ecaa0ebb2091d71392da1d9ca7c46 100644 (file)
@@ -37,6 +37,7 @@ struct progress_state {
 };
 
 static struct progress_state state;
+static volatile sig_atomic_t print_pending;
 
 /*
  * Simple progress print function.
@@ -63,12 +64,16 @@ static void progress_simple_init(void)
 #ifdef CONFIG_POSIX
 static void sigusr_print(int signal)
 {
-    printf("    (%3.2f/100%%)\n", state.current);
+    print_pending = 1;
 }
 #endif
 
 static void progress_dummy_print(void)
 {
+    if (print_pending) {
+        fprintf(stderr, "    (%3.2f/100%%)\n", state.current);
+        print_pending = 0;
+    }
 }
 
 static void progress_dummy_end(void)