From nobody Wed Apr 15 07:02:44 2026 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=1775532656; cv=none; d=zohomail.com; s=zohoarc; b=bK2zO3yF63npPpnOUhGHNj2UmNLkEWsyJH9i8sLC00wt6hsdPaSmgyXmBP//EXwHflKVvvc6Xoc1sTm7KOaXhQcppcET+sSu4+KTJy0eURpH4B1LCezm67JNU2+bbvBpQXW6z57KAysnoH0SpzNeEsrcJ260uA0ZZdAQuEljLnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532656; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=kR3eH221fM1WumcHReJaPlDp8hNMa6qkbGJK3jyDsig=; b=igdIO7ZWoBOzemNc1EF2X79hPzOiwBrNmYrl9oCsjzOOD2nANy4jADhznpS6ocrB0BM8Lix9/wZ6QbCnLjHiYI4JPMdXCSv4vksCdLn5N8InFNYaKj05LV7Zx602fQbhLZjWLq2z/tGhndnA8czcgmXC7USJpxrhm/IKrmea27M= 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 1775532656314287.36032624628365; Mon, 6 Apr 2026 20:30:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 359C03F8B3; Mon, 6 Apr 2026 23:30:55 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id A5C9141917; Mon, 6 Apr 2026 23:29:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 48A803F83C; Mon, 6 Apr 2026 23:29:25 -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 C34453F30F for ; Mon, 6 Apr 2026 23:29:24 -0400 (EDT) Received: from mx-prod-mc-05.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-47-Q_QB5-6TOvqbUNKoG8758A-1; Mon, 06 Apr 2026 23:29:23 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3CFE0195608B for ; Tue, 7 Apr 2026 03:29:22 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D171B1800762 for ; Tue, 7 Apr 2026 03:29:21 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532564; 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=kR3eH221fM1WumcHReJaPlDp8hNMa6qkbGJK3jyDsig=; b=eYY6bMrVya6myVwQqgCUJyGiZWdVCNeZHQ/aA4YnDwH09u1eYXjSamMFzALpQo2qCB6gVW iE3r8uLIUN+voT3n4XqRAEBiWHqat04JtufE4/Q/tvlJJ53PE0uIRe864OnUlx2RrrVcMs gh4vGRR8P+mmwbp3DvIwzw62hDrYS9g= X-MC-Unique: Q_QB5-6TOvqbUNKoG8758A-1 X-Mimecast-MFC-AGG-ID: Q_QB5-6TOvqbUNKoG8758A_1775532562 To: devel@lists.libvirt.org Subject: [PATCH 1/6] util: log the name of the log directory that couldn't be created Date: Mon, 6 Apr 2026 23:29:15 -0400 Message-ID: <20260407032920.242586-2-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CQlFPltWVg_O0kz6fxCoQdz2oeobQy5J3i8oiKygVe8_1775532562 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UPZEJICAPZDQATRQCEOLPRVVK5ATCWIY X-Message-ID-Hash: UPZEJICAPZDQATRQCEOLPRVVK5ATCWIY X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532657933158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump The message previously just said "Could not create log directory", but didn't provide the name of the directory, which could be helpful in determine why the failure occured. Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/util/virlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index c24dfa83c4..9f53c72975 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -178,7 +178,7 @@ virLogSetDefaultOutputToFile(const char *binary, bool p= rivileged) old_umask =3D umask(077); if (g_mkdir_with_parents(logdir, 0777) < 0) { umask(old_umask); - virReportSystemError(errno, "%s", _("Could not create log dire= ctory")); + virReportSystemError(errno, _("Could not create log directory = '%1$s'"), logdir); return -1; } umask(old_umask); --=20 2.53.0 From nobody Wed Apr 15 07:02:44 2026 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=1775532705; cv=none; d=zohomail.com; s=zohoarc; b=gfRp9dOcNs5r6vPda59I1EgbqfWP03zZcZZC5rD1/V0m2xjHBlYm5rtfCpNgkyUE0kd4Fii9wDgLvUumOAYRD4SSoG8ipde85aFWhLUT78pSJnakNyZK8NKN4u0xLstJN8xrQoPO8kF9xPTeUFBAY8iTptxjpz3X1F+5eyfgSIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532705; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=cHRJSLsgjXoZrL94LrJBtX3bUBjzZyRKCMV3zVXsXyk=; b=I1GgFVUT+kzqe039jVqXxLutGEm81eOe4cg/RPXcSBAUXNnDRL/B+maVYpmUQGin/K9j/5K3LbC5aLO+eMp2S+VAVg3oeGWo2HvvwjJT4sw8C+NcoeVshJnJZDrdWoIok9E2mDbTExj3AFdFjLS9H9GUuyD9NZS5bkGLBAFAOPI= 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 1775532705060718.4082816480003; Mon, 6 Apr 2026 20:31:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 2ED2E3F8A5; Mon, 6 Apr 2026 23:31:44 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1F3E741987; Mon, 6 Apr 2026 23:29:36 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 8EC0F3F359; Mon, 6 Apr 2026 23:29:25 -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 3ADD43F311 for ; Mon, 6 Apr 2026 23:29:25 -0400 (EDT) Received: from mx-prod-mc-03.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-295-KnzuR5WiOPW1Z99KMLM-xw-1; Mon, 06 Apr 2026 23:29:23 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9C681956046 for ; Tue, 7 Apr 2026 03:29:22 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6D92F180076A for ; Tue, 7 Apr 2026 03:29:22 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532564; 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=cHRJSLsgjXoZrL94LrJBtX3bUBjzZyRKCMV3zVXsXyk=; b=axTaEoc825pFXkYAlM8rk6WWYhE7qzpcZ3e3PKCaZsQYpJFrOrD7m7SYPs7XqEWq2HUjz/ 8UuYIzQAHFuZzi4SEYnJ1I1oTxipGcAzWxdEWT0OQ3DUB/pANZ6vHHB+pjsk9efmnR0lo4 IXH11yUo/0xoAhUBA0JMJXRaIO7o45o= X-MC-Unique: KnzuR5WiOPW1Z99KMLM-xw-1 X-Mimecast-MFC-AGG-ID: KnzuR5WiOPW1Z99KMLM-xw_1775532563 To: devel@lists.libvirt.org Subject: [PATCH 2/6] util: consistently use typedef virLogMetadata Date: Mon, 6 Apr 2026 23:29:16 -0400 Message-ID: <20260407032920.242586-3-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: o1YFAkhJhjWJm7BoGUPdYd3WLFnp8dHiu5D0esQMZWI_1775532563 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HOEMXDDKAVS5IOLDEK7DKUXRYCJDCPIF X-Message-ID-Hash: HOEMXDDKAVS5IOLDEK7DKUXRYCJDCPIF X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532706142158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump For some reason there were some uses of this struct where "struct _virLogMetadata" was used instead of just using the typedef "virLogMetadata" (they are both defined in the same file - virlog.h). Possibly at one point the struct was in virlog.c and outsiders could only see it as an opaque object, but even if that was the case, there are already cases of the typedef being used outside of virlog.c, and constinuing to use "struct _virLogMetadata" in some places both looks too much K&R 1st edition and might incorrectly imply to someone that there *is* data abstraction/hiding going on when there really isn't. So let's just always use plain virLogMetadata. Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/util/virlog.c | 12 ++++++------ src/util/virlog.h | 4 ++-- tests/testutils.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index 9f53c72975..30cb68fe7d 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -116,7 +116,7 @@ static void virLogOutputToFd(virLogSource *src, int linenr, const char *funcname, const char *timestamp, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *rawstr, const char *str, void *data); @@ -500,7 +500,7 @@ virLogVMessage(virLogSource *source, const char *filename, int linenr, const char *funcname, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *fmt, va_list vargs) { @@ -627,7 +627,7 @@ virLogMessage(virLogSource *source, const char *filename, int linenr, const char *funcname, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *fmt, ...) { va_list ap; @@ -646,7 +646,7 @@ virLogOutputToFd(virLogSource *source G_GNUC_UNUSED, int linenr G_GNUC_UNUSED, const char *funcname G_GNUC_UNUSED, const char *timestamp, - struct _virLogMetadata *metadata G_GNUC_UNUSED, + virLogMetadata *metadata G_GNUC_UNUSED, const char *rawstr G_GNUC_UNUSED, const char *str, void *data) @@ -746,7 +746,7 @@ virLogOutputToSyslog(virLogSource *source G_GNUC_UNUSED, int linenr G_GNUC_UNUSED, const char *funcname G_GNUC_UNUSED, const char *timestamp G_GNUC_UNUSED, - struct _virLogMetadata *metadata G_GNUC_UNUSED, + virLogMetadata *metadata G_GNUC_UNUSED, const char *rawstr G_GNUC_UNUSED, const char *str, void *data G_GNUC_UNUSED) @@ -890,7 +890,7 @@ virLogOutputToJournald(virLogSource *source, int linenr, const char *funcname, const char *timestamp G_GNUC_UNUSED, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *rawstr, const char *str G_GNUC_UNUSED, void *data) diff --git a/src/util/virlog.h b/src/util/virlog.h index 4f755c543b..77ba40b2e4 100644 --- a/src/util/virlog.h +++ b/src/util/virlog.h @@ -127,7 +127,7 @@ typedef void (*virLogOutputFunc) (virLogSource *src, int linenr, const char *funcname, const char *timestamp, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *rawstr, const char *str, void *data); @@ -170,7 +170,7 @@ void virLogMessage(virLogSource *source, const char *filename, int linenr, const char *funcname, - struct _virLogMetadata *metadata, + virLogMetadata *metadata, const char *fmt, ...) G_GNUC_PRINTF(7, 8); =20 bool virLogProbablyLogMessage(const char *str); diff --git a/tests/testutils.c b/tests/testutils.c index 14e5c56fcf..35571fb2ad 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -680,7 +680,7 @@ virtTestLogOutput(virLogSource *source G_GNUC_UNUSED, int lineno G_GNUC_UNUSED, const char *funcname G_GNUC_UNUSED, const char *timestamp, - struct _virLogMetadata *metadata G_GNUC_UNUSED, + virLogMetadata *metadata G_GNUC_UNUSED, const char *rawstr G_GNUC_UNUSED, const char *str, void *data) --=20 2.53.0 From nobody Wed Apr 15 07:02:44 2026 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=1775532747; cv=none; d=zohomail.com; s=zohoarc; b=CGqUwcn9hmgAC+e9S+Td6ExRo9s7EMyg6Ye3dQgaBDFvsr+/bVmrijchop0JjIZ8oThCVSCef2ARmxcDlpqZBu+iGPb007tiZKnDqz+294rWELYf5t8zL6pPvbVJIktx5al6jomJj6ftwSY3s259SaAA91xdmWtOPu2mzfQL9HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532747; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=K55o6fvkY29D3OaacZEhCgkaI3BTO5iIgw761UOfS/k=; b=XzeV7dX4a+LgNV5AbR6mcHnRAXnJoDblFU3g9gKU7rjOdwfAcZFvvmIwpkcdS0QPfFjGSrlaI4OQOkMnFTxtQwU6pL3VM4CUH+LoAiZXvAsUxyp8biv5k5elUQjNC1kk8OD3hZGwNvu/i0HnuTW/LvclwdMILbzbXIy3j/JDBTw= 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 1775532747320321.6353522851118; Mon, 6 Apr 2026 20:32:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 7CA22418A9; Mon, 6 Apr 2026 23:32:26 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 02F4041A24; Mon, 6 Apr 2026 23:29:38 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 2A12A3F35F; Mon, 6 Apr 2026 23:29:26 -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 BAC223F30F for ; Mon, 6 Apr 2026 23:29:25 -0400 (EDT) Received: from mx-prod-mc-05.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-31-29TGsyuuOkewesGYNb37HA-1; Mon, 06 Apr 2026 23:29:24 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 553CF195608A for ; Tue, 7 Apr 2026 03:29:23 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F38FB1800767 for ; Tue, 7 Apr 2026 03:29:22 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532565; 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=K55o6fvkY29D3OaacZEhCgkaI3BTO5iIgw761UOfS/k=; b=ENPFNFYYS6BTWMurI4tYpFnWbr1/Xu9citDyRmJyB00plzN0o4MUaEWTzaLF+Qt68bLEBR cExnCLxwYApG9B53ZyBfedkB1gexZZM6gl7TkqZuD2GymppeIh6/wBzNdZeMuGWxXZk4+Y Cc5G2uW19puJBG++7NoWhweBZPgXOxY= X-MC-Unique: 29TGsyuuOkewesGYNb37HA-1 X-Mimecast-MFC-AGG-ID: 29TGsyuuOkewesGYNb37HA_1775532563 To: devel@lists.libvirt.org Subject: [PATCH 3/6] util: eliminate duplicate code in virLogVMessage Date: Mon, 6 Apr 2026 23:29:17 -0400 Message-ID: <20260407032920.242586-4-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: j5mzkfsoiIIbjVw0aRuCgAhP3-3oRmryXv66i5dbJJo_1775532563 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JR5V22U5BHAFVJIBEH66FJMSET3V2QST X-Message-ID-Hash: JR5V22U5BHAFVJIBEH66FJMSET3V2QST X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532748210158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump The same several lines were repeated, once in a loop iterating through all log targets, and again to output to stderr when there are no log targets specified. This just moves those lines into a helper function, making it easier and less error prone to add additional info the the banner that is logged each time a daemon starts logging. Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/util/virlog.c | 127 ++++++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index 30cb68fe7d..7a9b1e75d5 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -479,6 +479,75 @@ virLogSourceUpdate(virLogSource *source) } =20 =20 +/** + * virLogToOneTarget: + * + * (these first several args are coming directly from the args of + * virLogVMessage() - you can find their description there) + * + * @source, @priority, @filename, @linenr, @funcname, @metadata: + * + * (the next 3 are created once during each call to virLogMMessage() and r= eused + * for each target) + * + * @timestamp: cached (during this one log to multiple targets) raw time + * @str: the log message formatted from what appears in the VIR_*() + or virReport*() call + * @msg: the formatted log message with function name, line number= , and + * priority added + * + * @outputFunc: pointer to function to call to output the data + * @data: private data used by @outputFunc (e.g. fd to write to) + * @needInit: pointer to bool that gets set to false once the + * once-per-daemon-run init message has been sent to this ta= rget + * + * If needInit is true, construct the strings to send the "init" + * message (a banner with software version, etc) to the log target + * using @outputFunc and set @needInit to false. Then send the current + * log message to the target (described by the other args) using + * @outputFunc. + */ +static void +virLogToOneTarget(virLogSource *source, + virLogPriority priority, + const char *filename, + int linenr, + const char *funcname, + virLogMetadata *metadata, + const char *timestamp, + const char *str, + const char *msg, + virLogOutputFunc outputFunc, + void *data, + bool *needInit) +{ + if (needInit) { + const char *rawinitmsg; + char *hoststr =3D NULL; + char *initmsg =3D NULL; + + virLogVersionString(&rawinitmsg, &initmsg); + outputFunc(&virLogSelf, VIR_LOG_INFO, + __FILE__, __LINE__, __func__, + timestamp, NULL, rawinitmsg, initmsg, + data); + VIR_FREE(initmsg); + + virLogHostnameString(&hoststr, &initmsg); + outputFunc(&virLogSelf, VIR_LOG_INFO, + __FILE__, __LINE__, __func__, + timestamp, NULL, hoststr, initmsg, + data); + VIR_FREE(hoststr); + VIR_FREE(initmsg); + needInit =3D false; + } + + outputFunc(source, priority, filename, linenr, funcname, + timestamp, metadata, str, msg, data); +} + + /** * virLogVMessage: * @source: where is that message coming from @@ -548,57 +617,19 @@ virLogVMessage(virLogSource *source, */ for (i =3D 0; i < virLogNbOutputs; i++) { if (priority >=3D virLogOutputs[i]->priority) { - if (virLogOutputs[i]->logInitMessage) { - const char *rawinitmsg; - char *hoststr =3D NULL; - char *initmsg =3D NULL; - virLogVersionString(&rawinitmsg, &initmsg); - virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, rawinitmsg, initmsg, - virLogOutputs[i]->data); - VIR_FREE(initmsg); - - virLogHostnameString(&hoststr, &initmsg); - virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, hoststr, initmsg, - virLogOutputs[i]->data); - VIR_FREE(hoststr); - VIR_FREE(initmsg); - virLogOutputs[i]->logInitMessage =3D false; - } - virLogOutputs[i]->f(source, priority, - filename, linenr, funcname, - timestamp, metadata, - str, msg, virLogOutputs[i]->data); + virLogToOneTarget(source, priority, filename, linenr, funcname= , metadata, + timestamp, str, msg, + virLogOutputs[i]->f, + virLogOutputs[i]->data, + &virLogOutputs[i]->logInitMessage); } } if (virLogNbOutputs =3D=3D 0) { - if (logInitMessageStderr) { - const char *rawinitmsg; - char *hoststr =3D NULL; - char *initmsg =3D NULL; - virLogVersionString(&rawinitmsg, &initmsg); - virLogOutputToFd(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, rawinitmsg, initmsg, - (void *) STDERR_FILENO); - VIR_FREE(initmsg); - - virLogHostnameString(&hoststr, &initmsg); - virLogOutputToFd(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, hoststr, initmsg, - (void *) STDERR_FILENO); - VIR_FREE(hoststr); - VIR_FREE(initmsg); - logInitMessageStderr =3D false; - } - virLogOutputToFd(source, priority, - filename, linenr, funcname, - timestamp, metadata, - str, msg, (void *) STDERR_FILENO); + virLogToOneTarget(source, priority, filename, linenr, funcname, me= tadata, + timestamp, str, msg, + virLogOutputToFd, + (void *) STDERR_FILENO, + &logInitMessageStderr); } virLogUnlock(); =20 --=20 2.53.0 From nobody Wed Apr 15 07:02:44 2026 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=1775532793; cv=none; d=zohomail.com; s=zohoarc; b=oLy+ioIsM5DdbplFYS/VKaC+FqRXmBtWZjBn/E3RH0u2Sg1VUKwuuQ+8gGQLE0JcU3I2Uy3UWLWzZKWETWHSpMezTxde++thZQasq+dAd4qfsV2eHkZQvrMA47w7g1KC8a3hQuXqVDZDUOuGDEKMKsGuMJhbkyOt3y2TrP5aqEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532793; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=n636oUKAgc+Bcf4YE0LS/LigT9WKdan3TElu1LQ0WnY=; b=Im63oTH1pc1gg5tr+wFlk5r0G/vTTU5Dluc+SUp4cWyLMNRXszvCU4a9b+80baun/eD6Iu3dvXbmrQMCRXKf2QoMkFZ3xJXrazFRX8GyTtbea6eOK+J//6mE9K7nIPRRcMjv4V1A81Pn1aUVC+5VXOjuGcogr5GX4uu9EDM61yU= 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 1775532793904854.7816753641825; Mon, 6 Apr 2026 20:33:13 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 1174F417EA; Mon, 6 Apr 2026 23:33:13 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 16C4041ACC; Mon, 6 Apr 2026 23:29:40 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id C72BA3F359; Mon, 6 Apr 2026 23:29:26 -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 4C01C3F30F for ; Mon, 6 Apr 2026 23:29:26 -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-97-l8oL7XJ7OF6TLJecWS5Yjg-1; Mon, 06 Apr 2026 23:29:24 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 DC34518005BB for ; Tue, 7 Apr 2026 03:29:23 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8650F1800762 for ; Tue, 7 Apr 2026 03:29:23 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532566; 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=n636oUKAgc+Bcf4YE0LS/LigT9WKdan3TElu1LQ0WnY=; b=El/tU07xKgsS1Q+sDZPZ1jtOE24DPkhKp+3aiZy4N9c08Zx4Ox9/th4al/V1AO2dVXjccu gc8T5ywNhWRTiF84xIb5CZPvX/4s8XTXiWKJO/jP4cgL4EZIuZ4wcPBrKgFp24YSGm13HI 35FoLERu3vQFWqwSvyR2mAO5PTAqb/c= X-MC-Unique: l8oL7XJ7OF6TLJecWS5Yjg-1 X-Mimecast-MFC-AGG-ID: l8oL7XJ7OF6TLJecWS5Yjg_1775532564 To: devel@lists.libvirt.org Subject: [PATCH 4/6] util: make it easier to add lines to the log "init banner" Date: Mon, 6 Apr 2026 23:29:18 -0400 Message-ID: <20260407032920.242586-5-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 66ca8Pa7EK2wQZPTULq2IFyRzgV1BgrtlgzWuh0Gogw_1775532564 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZFTP6FQEM7GB4DIRBBYE2AR2WRCUOHZL X-Message-ID-Hash: ZFTP6FQEM7GB4DIRBBYE2AR2WRCUOHZL X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532794394158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump The same thing happens for each line of the log banner: 1) A helper function is called that a) creates a "raw" string (just the desired info, e.g. version string) and b) calls virLogFormatString() for create a "cooked" version of the string (containing thread-id and log priority) 2) the outputFunc for the target is called with strings (a) and (b) By making a helper that does (1b) & (2), we can further reduce the amount of redundant code that needs to be written to add another line to the banner - now all we need to do is: 1) create the raw string 2) call the helper, sending it the raw string Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/util/virlog.c | 81 +++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index 7a9b1e75d5..4e95af047b 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -433,30 +433,6 @@ virLogFormatString(char **msg, } =20 =20 -static void -virLogVersionString(const char **rawmsg, - char **msg) -{ - *rawmsg =3D VIR_LOG_VERSION_STRING; - virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING); -} - -/* Similar to virGetHostname() but avoids use of error - * reporting APIs or logging APIs, to prevent recursion - */ -static void -virLogHostnameString(char **rawmsg, - char **msg) -{ - char *hoststr; - - hoststr =3D g_strdup_printf("hostname: %s", g_get_host_name()); - - virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr); - *rawmsg =3D hoststr; -} - - static void virLogSourceUpdate(virLogSource *source) { @@ -479,6 +455,33 @@ virLogSourceUpdate(virLogSource *source) } =20 =20 +/** + * virLogOneInitMsg: + * + * @str: the "raw" form of the string that's going to be logged + * + * (the args are all described in the caller - virLogToOneTarget() + * @timestamp,@outputFunc, @data + * + * send one "init message" (the lines that are at the beginning of the + * log when a new daemon starts) to one target. This just creates the + * "fancy" version of the string with thread-id and priority, and + * sends that, along with the "raw" version of the string, to the log + * target at INFO level. + */ +static void virLogOneInitMsg(const char *timestamp, + const char *str, + virLogOutputFunc outputFunc, + void *data) +{ + g_autofree char *msg =3D NULL; + + virLogFormatString(&msg, 0, NULL, VIR_LOG_INFO, str); + outputFunc(&virLogSelf, VIR_LOG_INFO, __FILE__, __LINE__, __func__, + timestamp, NULL, str, msg, data); +} + + /** * virLogToOneTarget: * @@ -522,24 +525,18 @@ virLogToOneTarget(virLogSource *source, bool *needInit) { if (needInit) { - const char *rawinitmsg; - char *hoststr =3D NULL; - char *initmsg =3D NULL; - - virLogVersionString(&rawinitmsg, &initmsg); - outputFunc(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, rawinitmsg, initmsg, - data); - VIR_FREE(initmsg); - - virLogHostnameString(&hoststr, &initmsg); - outputFunc(&virLogSelf, VIR_LOG_INFO, - __FILE__, __LINE__, __func__, - timestamp, NULL, hoststr, initmsg, - data); - VIR_FREE(hoststr); - VIR_FREE(initmsg); + g_autofree char *hoststr =3D NULL; + + /* put some useful info at the top of the log. Avoid calling + * any function that might end up reporting an error or + * otherwise logging something, to prevent recursion. + */ + + virLogOneInitMsg(timestamp, VIR_LOG_VERSION_STRING, outputFunc, da= ta); + + hoststr =3D g_strdup_printf("hostname: %s", g_get_host_name()); + virLogOneInitMsg(timestamp, hoststr, outputFunc, data); + needInit =3D false; } =20 --=20 2.53.0 From nobody Wed Apr 15 07:02:44 2026 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=1775532827; cv=none; d=zohomail.com; s=zohoarc; b=cEVFOa879NguCvQ6/xJg9pPVi0zGQodTmvVHNwEMqnsd957/iGnr/Yql+Cb8L6BsisdAu9xR1Ii7Ivb4VvQ7fjysEXicbil9BJIEUkMWXLQ+w1itK09HQea09x6itD1Ql7ZK4IZA/MOrZK+DsluNsl3s7Pb5VVzxZFrwyNAD2iw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532827; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=ewmJg78TR/wLg1eXUGTEF0nhsZ3Ryv3xY4Y9UPhVnO4=; b=aCUwvsLxJrjdY7xQ0xLQzp/K5ii8JFc0Kh0Je2cEwB2YSoF06cDLSLNctKlcHobzmReK8K5ulnPTWcwrwO0r+tdajx5VkVoT9/EUq/xXAmuKIaTB033/69siVUYydBDfvnNRGQXR6GgAgc3F022UbWcmx3h1yVlSPXw1hMaKaRs= 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 1775532827858999.2597039170416; Mon, 6 Apr 2026 20:33:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 04E073F932; Mon, 6 Apr 2026 23:33:47 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2998541B1D; Mon, 6 Apr 2026 23:29:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B9F663F967; Mon, 6 Apr 2026 23:29:33 -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 17AD53F8A2 for ; Mon, 6 Apr 2026 23:29:27 -0400 (EDT) Received: from mx-prod-mc-01.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-113-UckvNagkM8OYV4NQEzJJng-1; Mon, 06 Apr 2026 23:29:25 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DE1419560A3 for ; Tue, 7 Apr 2026 03:29:24 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 18FD11800762 for ; Tue, 7 Apr 2026 03:29:23 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532566; 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=ewmJg78TR/wLg1eXUGTEF0nhsZ3Ryv3xY4Y9UPhVnO4=; b=NkCxrEhzmhlUZeILQ5onRu696nvg1dxRS8EZrLcX1+D0Ig9ZLkyT0cIwlWw9gpD2qVSsB5 Iss0E87s3uKo9zb5WRGA4L3sRy+PMHxa6LY5imqgn9A/9OX0HPXJseaXNF6XRlDiWOswU4 W4qghHsVtActIXSz3YQuG9MmjIbntak= X-MC-Unique: UckvNagkM8OYV4NQEzJJng-1 X-Mimecast-MFC-AGG-ID: UckvNagkM8OYV4NQEzJJng_1775532564 To: devel@lists.libvirt.org Subject: [PATCH 5/6] util: add info to log banner about uid and user environment Date: Mon, 6 Apr 2026 23:29:19 -0400 Message-ID: <20260407032920.242586-6-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JYcvVxmTZ6EPJU8VUCRadZTkCIlpSa6nRPiw3DlHMEk_1775532564 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DADTQCDO2WMA577N4J64LHUHB6MFAXLE X-Message-ID-Hash: DADTQCDO2WMA577N4J64LHUHB6MFAXLE X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532828493158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump As libvirt is used more and more in unprivileged/session mode, file/socket permission errors have become more common. This patch adds an initial line to the log banner (the first thing sent to every log target after the process starts) stating whether the process is running privileged (as root) or unprivileged/session mode, and if the latter, it also provides the username and uid the process is running as. The idea is to expend this to include more generally useful info about the environment we're running in. (We just need to remember that in this context we can't call anything that could lead to recursively calling the logging system (i.e. you can't call any code that reports an error, or a VIR_WARN, etc)) Signed-off-by: Laine Stump Reviewed-by: Richard W.M. Jones --- src/util/virlog.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/virlog.c b/src/util/virlog.c index 4e95af047b..d5bd216241 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -525,6 +525,7 @@ virLogToOneTarget(virLogSource *source, bool *needInit) { if (needInit) { + uid_t uid =3D geteuid(); g_autofree char *hoststr =3D NULL; =20 /* put some useful info at the top of the log. Avoid calling @@ -537,6 +538,16 @@ virLogToOneTarget(virLogSource *source, hoststr =3D g_strdup_printf("hostname: %s", g_get_host_name()); virLogOneInitMsg(timestamp, hoststr, outputFunc, data); =20 + if (uid =3D=3D 0) { + virLogOneInitMsg(timestamp, "running in privileged/system mode= ", outputFunc, data); + } else { + g_autofree char *username =3D virGetUserName(uid); + g_autofree char *privstr =3D NULL; + + privstr =3D g_strdup_printf("running in unprivileged/session m= ode, user: %s, uid: %u", + username, uid); + virLogOneInitMsg(timestamp, privstr, outputFunc, data); + } needInit =3D false; } =20 --=20 2.53.0 From nobody Wed Apr 15 07:02:44 2026 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=1775532867; cv=none; d=zohomail.com; s=zohoarc; b=bkXW/CmAhDhvJhL5q7Foep/jH6P2gf/chwY7bM8hrI42BfEB8mIRog0WKj3r2bdeh3Y9fwHoKfg0F4dYIMQHO7NdxrE+o45FybCNvKOBPogoi19VRVT40OPxPj9s5WcBJOkS28ztBxTlEiz1ySpK8ir5vn7LJjtit7uDuqVaHIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775532867; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=JTSi1enohzyDLcP9PVYLVz6/9kIq/jo0OUQkH8GVjWo=; b=Yrv74zyKQvsy+H4RmQgwveBMQjgI9m20GlWvNHB78rsxyTT28jUoYNbSCaw6hx2uFr7fHRjLb7mIDDH9WfpY2ypDCNnd3ZDknPj3GldLNcSLfHfBGh4FJFMB8phPl0DZxMaxDEbGamQzV6E6lsQRcLMyULTbpHI93bL4QXO48Po= 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 1775532867274343.40315221433343; Mon, 6 Apr 2026 20:34:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 7E4CA3F8AC; Mon, 6 Apr 2026 23:34:26 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 6D18341B70; Mon, 6 Apr 2026 23:29:44 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 91AFB41AB0; Mon, 6 Apr 2026 23:29:39 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 856023F933 for ; Mon, 6 Apr 2026 23:29:27 -0400 (EDT) Received: from mx-prod-mc-03.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-522-6PEa-Tj1PsSDYNPc7NNtKA-1; Mon, 06 Apr 2026 23:29:25 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 007E81956050 for ; Tue, 7 Apr 2026 03:29:25 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9FD5F1800762 for ; Tue, 7 Apr 2026 03:29:24 +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=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1775532567; 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=JTSi1enohzyDLcP9PVYLVz6/9kIq/jo0OUQkH8GVjWo=; b=Yo5h7Ut60jc08VaiN+eFMHOK6hWel9E3bMb4UdMnr63TOHA1fdn3vCYa5Kc9DA1Yu3rz+t u8kvFwv4A0gGR/W4yiYbY8lUKzCFxOcs86eXntCZYU48+tq0B+oYPUpe5mUG6VtBVnTBWV N0FzdaUSj22BF+IuBwH1IA9VBHiC0tU= X-MC-Unique: 6PEa-Tj1PsSDYNPc7NNtKA-1 X-Mimecast-MFC-AGG-ID: 6PEa-Tj1PsSDYNPc7NNtKA_1775532565 To: devel@lists.libvirt.org Subject: [PATCH 6/6] util: add info about g_get_user_*_dir directories to log banner Date: Mon, 6 Apr 2026 23:29:20 -0400 Message-ID: <20260407032920.242586-7-laine@redhat.com> In-Reply-To: <20260407032920.242586-1-laine@redhat.com> References: <20260407032920.242586-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: WOYAL51U9VJtq-vQa70oUULmURtVn_h7vb0OrKVqqsI_1775532565 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TSQ6TTQBV3ABPRDVGQJOX4UKJEP6GLZR X-Message-ID-Hash: TSQ6TTQBV3ABPRDVGQJOX4UKJEP6GLZR X-MailFrom: laine@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 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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1775532868732158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump When running in session/unprivileged mode, nearly all paths are prefixed with the returns from one of the g_get_user_*_dir() functions, which in turn base their selected paths on the settings of a few items in the user's environment ($XDG_*, or a subdirectory of $HOME if the $XDG_* isn't set). This patch logs the settings of these environment variables and directories in the log banner in an attempt to help diagnose the problem when a file/socket open/create fails. Documentation for the glib g_get_user_*_dir() functions used by libvirt, and how they use the XDG Base Directory settings (along with $HOME) can be found here (current version as of the time of this patch): https://www.manpagez.com/html/glib/glib-2.56.0/glib-Miscellaneous-Utility= -Functions.php The XDG Base Directory Specification can be found here: https://specifications.freedesktop.org/basedir/latest/ Resolves: https://redhat.atlassian.net/browse/RHEL-70222 Resolves: https://redhat.atlassian.net/browse/RHEL-105490 Signed-off-by: Laine Stump --- We could obviously add more information here (or less); it's difficult to know where to draw the line. Also, the astute reviewer will notice that all this code is executed once for each log target - we could do it all once at a higher level and cache it if we really wanted to. I'm not sure if it's worth the trouble though). src/util/virlog.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/util/virlog.c b/src/util/virlog.c index d5bd216241..472ef3b261 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -543,10 +543,44 @@ virLogToOneTarget(virLogSource *source, } else { g_autofree char *username =3D virGetUserName(uid); g_autofree char *privstr =3D NULL; + g_autofree char *envHOME =3D NULL; + g_autofree char *envXDG_RUNTIME_DIR =3D NULL; + g_autofree char *envXDG_CONFIG_HOME =3D NULL; + g_autofree char *envXDG_CACHE_HOME =3D NULL; + + g_autofree char *envstr1 =3D NULL; + g_autofree char *envstr2 =3D NULL; + g_autofree char *envstr3 =3D NULL; + g_autofree char *envstr4 =3D NULL; + + if (!(envHOME =3D g_strdup(g_getenv("HOME")))) + envHOME =3D g_strdup("(unset)"); + if (!(envXDG_RUNTIME_DIR =3D g_strdup(g_getenv("XDG_RUNTIME_DI= R")))) + envXDG_RUNTIME_DIR =3D g_strdup("(unset)"); + if (!(envXDG_CONFIG_HOME =3D g_strdup(g_getenv("XDG_CONFIG_HOM= E")))) + envXDG_CONFIG_HOME =3D g_strdup("(unset)"); + if (!(envXDG_CACHE_HOME =3D g_strdup(g_getenv("XDG_CACHE_HOME"= )))) + envXDG_CACHE_HOME =3D g_strdup("(unset)"); =20 privstr =3D g_strdup_printf("running in unprivileged/session m= ode, user: %s, uid: %u", username, uid); virLogOneInitMsg(timestamp, privstr, outputFunc, data); + + envstr1 =3D g_strdup_printf("environment: HOME=3D'%s' (g_get_h= ome_dir: '%s'", + envHOME, g_get_home_dir()); + virLogOneInitMsg(timestamp, envstr1, outputFunc, data); + + envstr2 =3D g_strdup_printf(" XDG_RUNTIME_DIR=3D'%= s' (g_get_user_runtime_dir: '%s')", + envXDG_RUNTIME_DIR, g_get_user_runti= me_dir()); + virLogOneInitMsg(timestamp, envstr2, outputFunc, data); + + envstr3 =3D g_strdup_printf(" XDG_CONFIG_HOME=3D'%= s' (g_get_user_config_dir: '%s')", + envXDG_CONFIG_HOME, g_get_user_confi= g_dir()); + virLogOneInitMsg(timestamp, envstr3, outputFunc, data); + + envstr4 =3D g_strdup_printf(" XDG_CACHE_HOME=3D'%s= ' (g_get_user_cache_dir: '%s')", + envXDG_CACHE_HOME, g_get_user_cache_= dir()); + virLogOneInitMsg(timestamp, envstr4, outputFunc, data); } needInit =3D false; } --=20 2.53.0