jes.soren...@redhat.com writes: > From: Jes Sorensen <jes.soren...@redhat.com> > > This introduces support for dd-style progress reporting on POSIX > systems, if the user hasn't specified -p to report progress. If sent a > SIGUSR1, qemu-img will report current progress for commands that > support progress reporting. > > Signed-off-by: Jes Sorensen <jes.soren...@redhat.com> > --- > qemu-progress.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- > 1 files changed, 48 insertions(+), 5 deletions(-) > > diff --git a/qemu-progress.c b/qemu-progress.c > index 656e065..b4b751c 100644 > --- a/qemu-progress.c > +++ b/qemu-progress.c > @@ -26,12 +26,15 @@ > #include "osdep.h" > #include "sysemu.h" > #include <stdio.h> > +#include <signal.h> > > struct progress_state { > int enabled; > float current; > float last_print; > float min_skip; > + void (*print)(void); > + void (*end)(void); > }; > > static struct progress_state state; > @@ -51,20 +54,60 @@ static void progress_simple_print(void) > > static void progress_simple_end(void) > { > - if (state.enabled) { > - printf("\n"); > - } > + printf("\n"); > +} > + > +static void progress_simple_init(void) > +{ > + state.print = progress_simple_print; > + state.end = progress_simple_end; > +} > + > +#ifdef CONFIG_POSIX > +static void sigusr_print(int signal) > +{ > + printf(" (%3.2f/100%%)\n", state.current);
printf() is not async-signal-safe. I don't think you can safely call it in a signal handler. > +} > +#endif [...]