From nobody Tue Dec 16 11:43:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1740065282165501.16782070898023; Thu, 20 Feb 2025 07:28:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 12A481F58; Thu, 20 Feb 2025 10:28:01 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4A8272181; Thu, 20 Feb 2025 10:26:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id ED1751F5C; Thu, 20 Feb 2025 10:26:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 8A18021D1 for ; Thu, 20 Feb 2025 10:26:28 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-PnnGdijMPamG2KkSTiMyng-1; Thu, 20 Feb 2025 10:26:26 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 969EC18EB2CE for ; Thu, 20 Feb 2025 15:26:24 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 21B2819412A4 for ; Thu, 20 Feb 2025 15:26:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740065187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XC5IUIluMa0pZKK7Px5SFEr0fBYHqgcVcrZhg98O3pk=; b=XG6G9q/YJVmsknMIuXV0R+fBwXEijO11H1RAaXbNeWApK92HAxPYjAGkGRQv/k2hDLhZGX +xR/M5qkLQHWN29uROMKizX5GhjYiPz6WbiGy2UAtIcv7aLaB7M3qQ5XFhpCcp3QxtNmvM 6wmRCxy5Nm0eCqd21Ti3Eo0IcAY2dwc= X-MC-Unique: PnnGdijMPamG2KkSTiMyng-1 X-Mimecast-MFC-AGG-ID: PnnGdijMPamG2KkSTiMyng_1740065184 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 03/13] virsh: Do not format messages twice Date: Thu, 20 Feb 2025 16:26:05 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6Czp6-MJJ0TXhyb-lyXM8WcDobzSfS_LrWbtn6v220o_1740065184 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ODFD7KUQGF6Q5V23K5OU6OHCJVJOJBHQ X-Message-ID-Hash: ODFD7KUQGF6Q5V23K5OU6OHCJVJOJBHQ X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1740065285628019100 Content-Type: text/plain; charset="utf-8" The same message was formatted both in vshOutputLogFile and in vshDebug and vshError functions. This patch refactor vshOutputLogFile and its callers to only format each message once. Signed-off-by: Jiri Denemark --- tools/vsh.c | 27 +++++++++++---------------- tools/vsh.h | 4 +--- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 5f5e2f281d..1b650bdd9b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1967,13 +1967,12 @@ vshDebug(vshControl *ctl, int level, const char *fo= rmat, ...) if (level < ctl->debug) return; =20 - va_start(ap, format); - vshOutputLogFile(ctl, level, format, ap); - va_end(ap); - va_start(ap, format); str =3D g_strdup_vprintf(format, ap); va_end(ap); + + vshOutputLogFile(ctl, level, str); + fputs(str, stdout); fflush(stdout); } @@ -2118,11 +2117,12 @@ vshError(vshControl *ctl, const char *format, ...) va_list ap; g_autofree char *str =3D NULL; =20 - if (ctl !=3D NULL) { - va_start(ap, format); - vshOutputLogFile(ctl, VSH_ERR_ERROR, format, ap); - va_end(ap); - } + va_start(ap, format); + str =3D g_strdup_vprintf(format, ap); + va_end(ap); + + if (ctl) + vshOutputLogFile(ctl, VSH_ERR_ERROR, str); =20 /* Most output is to stdout, but if someone ran virsh 2>&1, then * printing to stderr will not interleave correctly with stdout @@ -2130,10 +2130,6 @@ vshError(vshControl *ctl, const char *format, ...) fflush(stdout); fputs(_("error: "), stderr); =20 - va_start(ap, format); - str =3D g_strdup_vprintf(format, ap); - va_end(ap); - fprintf(stderr, "%s\n", NULLSTR(str)); fflush(stderr); } @@ -2337,8 +2333,7 @@ vshOpenLogFile(vshControl *ctl) * Outputting an error to log file. */ void -vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, - va_list ap) +vshOutputLogFile(vshControl *ctl, int log_level, const char *msg) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *str =3D NULL; @@ -2381,7 +2376,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, cons= t char *msg_format, break; } virBufferAsprintf(&buf, "%s ", lvl); - virBufferVasprintf(&buf, msg_format, ap); + virBufferAddStr(&buf, msg); virBufferTrim(&buf, "\n"); virBufferAddChar(&buf, '\n'); =20 diff --git a/tools/vsh.h b/tools/vsh.h index 7de9fa2f09..1c7370dd4f 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -241,9 +241,7 @@ struct _vshCmdGrp { void vshError(vshControl *ctl, const char *format, ...) G_GNUC_PRINTF(2, 3); void vshOpenLogFile(vshControl *ctl); -void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, - va_list ap) - G_GNUC_PRINTF(3, 0); +void vshOutputLogFile(vshControl *ctl, int log_level, const char *msg); void vshCloseLogFile(vshControl *ctl); =20 int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, --=20 2.48.1