Received: from eggs.gnu.org ([140.186.70.92]:32898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF7OJ-0002S1-Bo for qemu-devel@nongnu.org; Wed, 27 Apr 2011 12:15:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QF7OF-0000Bq-Gv for qemu-devel@nongnu.org; Wed, 27 Apr 2011 12:15:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF7OF-0000Bk-4K for qemu-devel@nongnu.org; Wed, 27 Apr 2011 12:14:59 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3RGEuQQ017532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 27 Apr 2011 12:14:56 -0400 From: Markus Armbruster References: <1303907511-4092-1-git-send-email-Jes.Sorensen@redhat.com> <1303907511-4092-2-git-send-email-Jes.Sorensen@redhat.com> Date: Wed, 27 Apr 2011 18:14:53 +0200 In-Reply-To: <1303907511-4092-2-git-send-email-Jes.Sorensen@redhat.com> (Jes Sorensen's message of "Wed, 27 Apr 2011 14:31:50 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 1/2] Add dd-style SIGUSR1 progress reporting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jes.Sorensen@redhat.com Cc: kwolf@redhat.com, qemu-devel@nongnu.org Jes.Sorensen@redhat.com writes: > From: Jes Sorensen > > 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 > --- > 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 > +#include > > 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 [...]