From nobody Sun Dec 14 06:20:07 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=1751634456; cv=none; d=zohomail.com; s=zohoarc; b=HQI46mQHLGiR6g6TEMZ94rQjzj/+XlDAC00r2i0Gvz3iwsdHPUaOo8J72L6SyOECZmhSVmgvO0RmJRJ20MsETQzrCwiRU8vJ7H91rF17rhGoahJ6YbPP7oVvNfXwN1SQuan0U6uD3nYDK8CVv4ty4YogkFDqa3f9WG5cYzzbNJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751634456; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=jx27nPkMNxhAOxuC2UwrCM0lfkF0YU4HB58rUkg2Wy4=; b=fEspykW9Ft56fgP/HkTrQacaxuDUuoYJIkT8Gx59KCWdbb9HtExjSv+7F4pBZoS1Ikn7wFN9B11GTxFUN3oi2pbrdXUCyDkcDAUIvkt7l75CrOvCkt/XE2KAxVlH+4Gu1eFbxwOHepr8GBj4s3Oq/jLXE++hXlCf52PWEiR/7XM= 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 1751634456186110.46346503883694; Fri, 4 Jul 2025 06:07:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3FBC3999; Fri, 4 Jul 2025 09:07:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B52BF1427; Fri, 4 Jul 2025 09:06:20 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BB0A7DDF; Fri, 4 Jul 2025 09:06:11 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0E8D4DE5 for ; Fri, 4 Jul 2025 09:06:11 -0400 (EDT) Received: from mx-prod-mc-04.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-100-ElubMqKDMRGZcnBqE_Ia4g-1; Fri, 04 Jul 2025 09:06:09 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 43B0E1978C9A for ; Fri, 4 Jul 2025 13:06:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 91026180045B for ; Fri, 4 Jul 2025 13:06:07 +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=2.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751634370; 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=Q6zAUpQZCLNbn3ZakRHJt2i+FZNAT+CJNIxRgvrfkQ8=; b=MggOnuLLieGIi5F3GXVZdk8OSnmUfKOBbVziLgWCX+DAOSugIrBMTPDc+peK0FC3mDctid RxqqZOSVU+qKyiiWJv7aa7q1d1VA5bZ5nLorxJDvz5krV94itjPEFI5PclXva0bIxluKYe tXq3Qi5GVMe1vcGVJ+1aDv9IOnfs02c= X-MC-Unique: ElubMqKDMRGZcnBqE_Ia4g-1 X-Mimecast-MFC-AGG-ID: ElubMqKDMRGZcnBqE_Ia4g_1751634368 To: devel@lists.libvirt.org Subject: [PATCH 2/6] nss: Move logging into a separate file and turn it temporarily on Date: Fri, 4 Jul 2025 15:05:31 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: h4-gia_sz00S6mjkuG58fsmiHsRUyvnZj-jeijaGJFQ_1751634368 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Z4VUTVBUVVNBQTUE4ZLFL7AZWLHLNPIM X-Message-ID-Hash: Z4VUTVBUVVNBQTUE4ZLFL7AZWLHLNPIM X-MailFrom: mprivozn@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: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751634459764116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Currently, when somebody wants to debug the NSS plugin, they have to change a line in libvirt_nss.h (to enable debug printings) and recompile the module. This may work for us, developers, but we can not expect this from users. For now, this turns debug printings unconditionally on. Making it conditional on an envvar is handled in the next commit. Signed-off-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tools/nss/libvirt_nss.h | 30 +-------------- tools/nss/libvirt_nss_log.c | 76 +++++++++++++++++++++++++++++++++++++ tools/nss/libvirt_nss_log.h | 38 +++++++++++++++++++ tools/nss/meson.build | 1 + 5 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 tools/nss/libvirt_nss_log.c create mode 100644 tools/nss/libvirt_nss_log.h diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 1303a0ce7e..541b2c5016 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1421,7 +1421,7 @@ exclude_file_name_regexp--sc_prohibit_canonicalize_fi= le_name =3D \ ^(build-aux/syntax-check\.mk|tests/virfilemock\.c)$$ =20 exclude_file_name_regexp--sc_prohibit_raw_allocation =3D \ - ^(docs/advanced-tests\.rst|src/util/viralloc\.[ch]|examples/.*|tests/(se= curityselinuxhelper|(vircgroup|nss)mock|commandhelper)\.c|tools/wireshark/s= rc/packet-libvirt\.c|tools/nss/libvirt_nss(_leases|_macs)?\.[ch])$$ + ^(docs/advanced-tests\.rst|src/util/viralloc\.[ch]|examples/.*|tests/(se= curityselinuxhelper|(vircgroup|nss)mock|commandhelper)\.c|tools/wireshark/s= rc/packet-libvirt\.c|tools/nss/libvirt_nss(_leases|_log|_macs)?\.[ch])$$ =20 exclude_file_name_regexp--sc_prohibit_readlink =3D \ ^src/(util/virutil|lxc/lxc_container)\.c$$ diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h index 84db044409..e09fce9715 100644 --- a/tools/nss/libvirt_nss.h +++ b/tools/nss/libvirt_nss.h @@ -31,35 +31,7 @@ #include #include =20 - -#if 0 -# include -# include -# include -# define NULLSTR(s) ((s) ? (s) : "") -# define ERROR(...) \ -do { \ - int saved_errno =3D errno; \ - const size_t ebuf_size =3D 512; \ - g_autofree char *ebuf =3D calloc(ebuf_size, sizeof(*ebuf)); \ - if (ebuf) \ - strerror_r(saved_errno, ebuf, ebuf_size); \ - fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, " : %s\n", NULLSTR(ebuf)); \ - fprintf(stderr, "\n"); \ -} while (0) - -# define DEBUG(...) \ -do { \ - fprintf(stderr, "DEBUG %s:%d : ", __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ -} while (0) -#else -# define ERROR(...) do { } while (0) -# define DEBUG(...) do { } while (0) -#endif +#include "libvirt_nss_log.h" =20 #if !defined(LIBVIRT_NSS_GUEST) # define NSS_NAME(s) _nss_libvirt_##s##_r diff --git a/tools/nss/libvirt_nss_log.c b/tools/nss/libvirt_nss_log.c new file mode 100644 index 0000000000..0863897c07 --- /dev/null +++ b/tools/nss/libvirt_nss_log.c @@ -0,0 +1,76 @@ +/* + * libvirt_nss_log: Logging for Name Service Switch plugin + * + * Copyright (C) 2025 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include +#include +#include +#include + +#include "libvirt_nss_log.h" +#include "libvirt_nss.h" + +#define NULLSTR(s) ((s) ? (s) : "") + +static const char * __attribute__((returns_nonnull)) +nssLogPriorityToString(nssLogPriority prio) +{ + switch (prio) { + case NSS_DEBUG: + return "DEBUG"; + case NSS_ERROR: + return "ERROR"; + } + + return ""; +} + +void +nssLog(nssLogPriority prio, + const char *func, + int linenr, + const char *fmt, ...) +{ + int saved_errno =3D errno; + const size_t ebuf_size =3D 512; + g_autofree char *ebuf =3D NULL; + va_list ap; + + fprintf(stderr, "%s %s:%d : ", nssLogPriorityToString(prio), func, lin= enr); + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + switch (prio) { + case NSS_DEBUG: + break; + + case NSS_ERROR: + ebuf =3D calloc(ebuf_size, sizeof(*ebuf)); + if (ebuf) + strerror_r(saved_errno, ebuf, ebuf_size); + fprintf(stderr, " : %s", NULLSTR(ebuf)); + break; + } + + fprintf(stderr, "\n"); +} diff --git a/tools/nss/libvirt_nss_log.h b/tools/nss/libvirt_nss_log.h new file mode 100644 index 0000000000..bac64d4bc7 --- /dev/null +++ b/tools/nss/libvirt_nss_log.h @@ -0,0 +1,38 @@ +/* + * libvirt_nss_log: Logging for Name Service Switch plugin + * + * Copyright (C) 2025 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +typedef enum { + NSS_DEBUG, + NSS_ERROR, +} nssLogPriority; + +#define DEBUG(...) \ + nssLog(NSS_DEBUG, __FUNCTION__, __LINE__, __VA_ARGS__) + +#define ERROR(...) \ + nssLog(NSS_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__) + +void +nssLog(nssLogPriority prio, + const char *func, + int linenr, + const char *fmt, ...) __attribute__ ((format(printf, 4, 5))); diff --git a/tools/nss/meson.build b/tools/nss/meson.build index 38bba2d616..5893952adc 100644 --- a/tools/nss/meson.build +++ b/tools/nss/meson.build @@ -13,6 +13,7 @@ endif nss_sources =3D [ 'libvirt_nss.c', 'libvirt_nss_leases.c', + 'libvirt_nss_log.c', ] =20 nss_guest_sources =3D [ --=20 2.49.0