qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe


From: Jes . Sorensen
Subject: [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe
Date: Thu, 28 Apr 2011 12:00:13 +0200

From: Jes Sorensen <address@hidden>

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 <address@hidden>
---
 qemu-progress.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/qemu-progress.c b/qemu-progress.c
index e1feb89..27a2310 100644
--- a/qemu-progress.c
+++ b/qemu-progress.c
@@ -32,6 +32,7 @@ struct progress_state {
     float current;
     float last_print;
     float min_skip;
+    int print_pending;
     void (*print)(void);
     void (*end)(void);
 };
@@ -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);
+    state.print_pending = 1;
 }
 #endif
 
 static void progress_dummy_print(void)
 {
+    if (state.print_pending) {
+        fprintf(stderr, "    (%3.2f/100%%)\n", state.current);
+        state.print_pending = 0;
+    }
 }
 
 static void progress_dummy_end(void)
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]