From nobody Sun Sep 28 15:29:09 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758798356; cv=none; d=zohomail.com; s=zohoarc; b=agZ68TlLLnUiZIhj6cMXHLW7ssyS/9OWvo7R3bePwHREL7qF+/6a7cmiNRmhGNR7+dy8dd1bE7uH3O4WLgKi9NISWPkBU3+//V3mDCI4xdRWx0E4lzUg8bparKpzgsNEYMkUJQyfuzbYpb6WYABgs5zAU6mpflfJP5BNlnDE6R8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758798356; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=BZnC6QiBd1lbYvGRWS1LNh6guPnvUdl77jy61phbsAI=; b=fYSYXGxrwQGPaRj9pfcLNbNysfGj/fq/j78pglqSHtyp1AP/5oBuCEvSgizMcoez/c5IhmSIvSUC1IKbdChumgYecJ7WoSoo2s9Ol5A4xo90VCP8YetH1tO2Uk2m2ncMpBGSiRqCJU43fWTRH/8fIa8yDuTH+/yxbeZvKDFPG4g= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758798356810562.3059967577097; Thu, 25 Sep 2025 04:05:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CAFE4418BC; Thu, 25 Sep 2025 07:05:55 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 41A28445CA; Thu, 25 Sep 2025 05:50:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id E46AE4409F; Thu, 25 Sep 2025 05:48:56 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id AFBDE43E5B for ; Thu, 25 Sep 2025 05:46:58 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-EHxMsjApNcy_vYIeoM-fMA-1; Thu, 25 Sep 2025 05:46:53 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ACBE21800299; Thu, 25 Sep 2025 09:46:51 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9D4EA300021A; Thu, 25 Sep 2025 09:46:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BZnC6QiBd1lbYvGRWS1LNh6guPnvUdl77jy61phbsAI=; b=b9rfxcKJU516oNGMwkPwW5CnD1A00tOaYQBuWtb6LaVAcEYQHOCzrNFvcv/9DZLj8h9Qx2 Hq6pu7+f6rip+b0UKks60GNBhlBzeE2ihhYJ+VZBU6/Q2h8T6scWvXiCD51Hkfk9Ufdy7O VMkoZ4fPQPwuL2G5UKhZdNZpUcF0sxE= X-MC-Unique: EHxMsjApNcy_vYIeoM-fMA-1 X-Mimecast-MFC-AGG-ID: EHxMsjApNcy_vYIeoM-fMA_1758793611 To: qemu-devel@nongnu.org Subject: [PATCH v4 21/23] util: add support for formatting a program name in messages Date: Thu, 25 Sep 2025 10:44:39 +0100 Message-ID: <20250925094441.1651372-22-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Message-ID-Hash: H22HSSHGIFGOI34OA4QI3KIKZWBT57FQ X-Message-ID-Hash: H22HSSHGIFGOI34OA4QI3KIKZWBT57FQ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758798359350116600 The error_report function can include the program name in any messages it prints. The qemu_log function has no equivalent behaviour. This introduces support for a "program name" in the new messages API, which will be included by default for all binaries. This change tweaks the output of the error_report function, adding a space between the program name and the location info. The qemu_log function will gain the program name. This can be easily seen with the 'log' trace backend, and how it is now more closely matching error_report output. Before: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qcrypto_tls_creds_x509_load TLS creds x509 load creds=3D0x5584e13937f0 di= r=3Dfish qcrypto_tls_creds_get_path TLS creds path creds=3D0x5584e13937f0 filename= =3Dca-cert.pem path=3D qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No suc= h file or directory After: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qemu-system-x86_64: qcrypto_tls_creds_x509_load TLS creds x509 load creds= =3D0x5584e13937f0 dir=3Dfish qemu-system-x86_64: qcrypto_tls_creds_get_path TLS creds path creds=3D0x5= 584e13937f0 filename=3Dca-cert.pem path=3D qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No suc= h file or directory Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/message.h | 1 + system/vl.c | 2 +- tests/unit/test-error-report.c | 5 +++-- util/error-report.c | 4 ---- util/message.c | 9 ++++++++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/qemu/message.h b/include/qemu/message.h index cfc3c92648..b8518d06be 100644 --- a/include/qemu/message.h +++ b/include/qemu/message.h @@ -6,6 +6,7 @@ enum QMessageFormatFlags { QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), QMESSAGE_FORMAT_WORKLOAD_NAME =3D (1 << 1), + QMESSAGE_FORMAT_PROGRAM_NAME =3D (1 << 2), }; =20 /** diff --git a/system/vl.c b/system/vl.c index 56829880f6..0ac1b11caf 100644 --- a/system/vl.c +++ b/system/vl.c @@ -815,7 +815,7 @@ static void realtime_init(void) =20 static void configure_msg(QemuOpts *opts) { - int flags =3D 0; + int flags =3D QMESSAGE_FORMAT_PROGRAM_NAME; if (qemu_opt_get_bool(opts, "timestamp", false)) { flags |=3D QMESSAGE_FORMAT_TIMESTAMP; } diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c index 78f8b57660..3987a8ed25 100644 --- a/tests/unit/test-error-report.c +++ b/tests/unit/test-error-report.c @@ -48,7 +48,7 @@ test_error_report_loc(void) g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr("\ -test-error-report:some-file.c:7717: test error1*\ +test-error-report: some-file.c:7717: test error1*\ test-error-report: test error2*\ "); } @@ -91,7 +91,8 @@ static void test_error_report_timestamp(void) { if (g_test_subprocess()) { - qmessage_set_format(QMESSAGE_FORMAT_TIMESTAMP); + qmessage_set_format(QMESSAGE_FORMAT_TIMESTAMP | + QMESSAGE_FORMAT_PROGRAM_NAME); warn_report("warn"); error_report("err"); return; diff --git a/util/error-report.c b/util/error-report.c index edb04585aa..b010f97bda 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -176,10 +176,6 @@ static void print_loc(Monitor *cur) int i; const char *const *argp; =20 - if (!cur && g_get_prgname()) { - error_printf_mon(NULL, "%s:", g_get_prgname()); - sep =3D " "; - } switch (cur_loc->kind) { case LOC_CMDLINE: argp =3D cur_loc->ptr; diff --git a/util/message.c b/util/message.c index a91c008e08..1db9254733 100644 --- a/util/message.c +++ b/util/message.c @@ -5,7 +5,7 @@ #include "qemu/message.h" #include "monitor/monitor.h" =20 -static int message_format; +static int message_format =3D QMESSAGE_FORMAT_PROGRAM_NAME; static char *message_workloadname; =20 void qmessage_set_format(int flags) @@ -30,4 +30,11 @@ void qmessage_context_print(FILE *fp) message_workloadname) { fprintf(fp, "%s ", message_workloadname); } + + if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { + const char *pgnamestr =3D g_get_prgname(); + if (pgnamestr) { + fprintf(fp, "%s: ", pgnamestr); + } + } } --=20 2.50.1