Received: from eggs.gnu.org ([140.186.70.92]:50143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFPLq-0001xk-P8 for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:25:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QFPLp-0004k2-OP for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:25:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFPLp-0004jy-Bs for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:25:41 -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 p3SBPdSI015837 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Apr 2011 07:25:40 -0400 From: Markus Armbruster References: <1303984813-20169-1-git-send-email-Jes.Sorensen@redhat.com> Date: Thu, 28 Apr 2011 13:25:37 +0200 In-Reply-To: <1303984813-20169-1-git-send-email-Jes.Sorensen@redhat.com> (Jes Sorensen's message of "Thu, 28 Apr 2011 12:00:13 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] qemu-progress.c: printf isn't signal safe 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 > > 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 > --- > 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)