From nobody Thu Apr 25 11:22:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523865360105856.258452909119; Mon, 16 Apr 2018 00:56:00 -0700 (PDT) Received: from localhost ([::1]:53804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7yzT-0008Su-5E for importer@patchew.org; Mon, 16 Apr 2018 03:55:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7yyJ-0007wm-Tn for qemu-devel@nongnu.org; Mon, 16 Apr 2018 03:54:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f7yyF-0005KE-Us for qemu-devel@nongnu.org; Mon, 16 Apr 2018 03:54:43 -0400 Received: from mail139-154.mail.alibaba.com ([198.11.139.154]:26371) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f7yyF-0005Fm-KJ for qemu-devel@nongnu.org; Mon, 16 Apr 2018 03:54:39 -0400 Received: from localhost.localdomain(mailfrom:zhenwei.pi@youruncloud.com fp:SMTPD_---.BiJBeu6_1523864935) by smtp.aliyun-inc.com(10.147.43.230); Mon, 16 Apr 2018 15:48:55 +0800 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.06653786|-1; CH=green; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03302; MF=zhenwei.pi@youruncloud.com; NM=1; PH=DS; RN=5; RT=5; SR=0; TI=SMTPD_---.BiJBeu6_1523864935; From: zhenwei pi To: pbonzini@redhat.com, mreitz@redhat.com, kwolf@redhat.com Date: Mon, 16 Apr 2018 15:46:28 +0800 Message-Id: <1523864788-15800-1-git-send-email-zhenwei.pi@youruncloud.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.11.139.154 Subject: [Qemu-devel] [PATCH] qemu-progress: redirct qemu progress message to another file stream X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhenwei.pi@youruncloud.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" currently qemu progress message only print into stdout, and other thread may print some log into stdout at the same time. add a new api qemu_progress_set_output to redirect progress message to another file stream. Signed-off-by: zhenwei pi --- include/qemu-common.h | 1 + util/qemu-progress.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 8a4f63c..511e7e0 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -128,6 +128,7 @@ ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t= bytes, bool do_send); void qemu_progress_init(int enabled, float min_skip); void qemu_progress_end(void); void qemu_progress_print(float delta, int max); +int qemu_progress_set_output(FILE *output); const char *qemu_get_vm_name(void); =20 #define QEMU_FILE_TYPE_BIOS 0 diff --git a/util/qemu-progress.c b/util/qemu-progress.c index 3c2223c..dd7aa52 100644 --- a/util/qemu-progress.c +++ b/util/qemu-progress.c @@ -31,6 +31,7 @@ struct progress_state { float min_skip; void (*print)(void); void (*end)(void); + FILE *output; }; =20 static struct progress_state state; @@ -43,17 +44,18 @@ static volatile sig_atomic_t print_pending; */ static void progress_simple_print(void) { - printf(" (%3.2f/100%%)\r", state.current); - fflush(stdout); + fprintf(state.output, " (%3.2f/100%%)\r", state.current); + fflush(state.output); } =20 static void progress_simple_end(void) { - printf("\n"); + fprintf(state.output, "\n"); } =20 static void progress_simple_init(void) { + state.output =3D stdout; state.print =3D progress_simple_print; state.end =3D progress_simple_end; } @@ -129,6 +131,20 @@ void qemu_progress_end(void) } =20 /* + * Redirect progress into another file stream. + * @output is the new file stream. + */ +int qemu_progress_set_output(FILE *output) +{ + if (!output) { + return -EINVAL; + } + + state.output =3D output; + return 0; +} + +/* * Report progress. * @delta is how much progress we made. * If @max is zero, @delta is an absolut value of the total job done. --=20 2.7.4