qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe
@ 2011-04-28 10:00 Jes.Sorensen
  2011-04-28 11:25 ` Markus Armbruster
  0 siblings, 1 reply; 2+ messages in thread
From: Jes.Sorensen @ 2011-04-28 10:00 UTC (permalink / raw)
  To: kwolf; +Cc: armbru, qemu-devel

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(-)

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe
  2011-04-28 10:00 [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe Jes.Sorensen
@ 2011-04-28 11:25 ` Markus Armbruster
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Armbruster @ 2011-04-28 11:25 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: kwolf, qemu-devel

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.
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  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;

To be pedantically correct: volatile sig_atomic_t print_pending

>      void (*print)(void);
>      void (*end)(void);
>  };

I don't care for wrapping a file's static global variables in a struct,
but I guess that's water under the bridge now.

> @@ -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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-28 11:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-28 10:00 [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe Jes.Sorensen
2011-04-28 11:25 ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).