Patchwork [v2] qemu-progress.c: printf isn't signal safe

login
register
mail settings
Submitter Jes Sorensen
Date April 28, 2011, 11:58 a.m.
Message ID <1303991910-28052-1-git-send-email-Jes.Sorensen@redhat.com>
Download mbox | patch
Permalink /patch/93208/
State New
Headers show

Comments

Jes Sorensen - April 28, 2011, 11:58 a.m.
From: Jes Sorensen <Jes.Sorensen@redhat.com>

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>
---
 qemu-progress.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
Markus Armbruster - April 28, 2011, 12:53 p.m.
Jes.Sorensen@redhat.com writes:

> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> 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.

Looks good now.
Kevin Wolf - April 29, 2011, 11:21 a.m.
Am 28.04.2011 13:58, schrieb Jes.Sorensen@redhat.com:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> 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>

Thanks, applied to the block branch.

Kevin

Patch

diff --git a/qemu-progress.c b/qemu-progress.c
index e1feb89..a4894c0 100644
--- a/qemu-progress.c
+++ b/qemu-progress.c
@@ -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)