From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFPsL-0000F3-42 for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:59:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QFPsK-0001Ra-8Y for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:59:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFPsK-0001RO-08 for qemu-devel@nongnu.org; Thu, 28 Apr 2011 07:59:16 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3SBxE9s007970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Apr 2011 07:59:14 -0400 From: Jes.Sorensen@redhat.com Date: Thu, 28 Apr 2011 13:58:30 +0200 Message-Id: <1303991910-28052-1-git-send-email-Jes.Sorensen@redhat.com> Subject: [Qemu-devel] [PATCH v2] qemu-progress.c: printf isn't signal safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org 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..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) -- 1.7.4.4