From patchwork Tue Jun 29 10:11:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 44044 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41F7C3980802 for ; Tue, 29 Jun 2021 10:14:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41F7C3980802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624961671; bh=Wf9no1j811w6litDT3xaCRb2kh0G0U7KT7TMAnC8+c4=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ApO4/LSu5ArP/29LPGjej7ACUcRTzaznSFNyGvR7K7hSp2zFfRlrLuhr8QzBhrX/6 71/FLpvjDIJkrr2VnMiEYFKFPsbYM0q2KbOQjMoOQzSpwK36fs5Kw4TB2zd18tXXlZ ba7/niCQ6QznNneMj8tIRXUTP8mQIJPto5YrlWEw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5C7FB3973065 for ; Tue, 29 Jun 2021 10:11:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C7FB3973065 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-qZWa5Ht3Pyuu7VeaaI5Jjg-1; Tue, 29 Jun 2021 06:11:37 -0400 X-MC-Unique: qZWa5Ht3Pyuu7VeaaI5Jjg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35744100C611 for ; Tue, 29 Jun 2021 10:11:37 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-228.ams2.redhat.com [10.36.112.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C8D1100164A for ; Tue, 29 Jun 2021 10:11:36 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 4/7] nss_files: Allocate nscd file registration data on the heap In-Reply-To: References: X-From-Line: ee2dbe88a6e5ce5ba86fed606518efeab39dfa8b Mon Sep 17 00:00:00 2001 Message-Id: Date: Tue, 29 Jun 2021 12:11:34 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is only needed if nss_files is loaded by nscd. Before: text data bss dec hex filename 767 0 24952 25719 6477 nss/files-init.os After: text data bss dec hex filename 666 0 0 666 29a nss/files-init.os Using PATH_MAX bytes unconditionally for the directory name is wasteful, but fixing that would constitute another break of this semi-public ABI. (The other issue is that with symbolic links, an arbitrary set of parent directories may need watching, not just a single one.) Reviewed-by: Adhemerval Zanella --- nss/nss_files/files-init.c | 54 ++++++++++++++------------------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c index cc22330640..36d5ebce1f 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -24,44 +24,30 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) -#define PWD_FILENAME "/etc/passwd" -define_traced_file (pwd, PWD_FILENAME); - -#define GRP_FILENAME "/etc/group" -define_traced_file (grp, GRP_FILENAME); - -#define HST_FILENAME "/etc/hosts" -define_traced_file (hst, HST_FILENAME); - -#define RESOLV_FILENAME "/etc/resolv.conf" -define_traced_file (resolv, RESOLV_FILENAME); - -#define SERV_FILENAME "/etc/services" -define_traced_file (serv, SERV_FILENAME); - -#define NETGR_FILENAME "/etc/netgroup" -define_traced_file (netgr, NETGR_FILENAME); +static void +register_file (void (*cb) (size_t, struct traced_file *), + int db, const char *path, int crinit) +{ + size_t pathlen = strlen (path) + 1; + struct traced_file *file = malloc (sizeof (struct traced_file) + pathlen); + /* Do not register anything on memory allocation file. nscd will + fail soon anyway. */ + if (file != NULL) + { + init_traced_file (file, path, crinit); + cb (db, file); + } +} void _nss_files_init (void (*cb) (size_t, struct traced_file *)) { - init_traced_file (&pwd_traced_file.file, PWD_FILENAME, 0); - cb (pwddb, &pwd_traced_file.file); - - init_traced_file (&grp_traced_file.file, GRP_FILENAME, 0); - cb (grpdb, &grp_traced_file.file); - - init_traced_file (&hst_traced_file.file, HST_FILENAME, 0); - cb (hstdb, &hst_traced_file.file); - - init_traced_file (&resolv_traced_file.file, RESOLV_FILENAME, 1); - cb (hstdb, &resolv_traced_file.file); - - init_traced_file (&serv_traced_file.file, SERV_FILENAME, 0); - cb (servdb, &serv_traced_file.file); - - init_traced_file (&netgr_traced_file.file, NETGR_FILENAME, 0); - cb (netgrdb, &netgr_traced_file.file); + register_file (cb, pwddb, "/etc/passwd", 0); + register_file (cb, grpdb, "/etc/group", 0); + register_file (cb, hstdb, "/etc/hosts", 0); + register_file (cb, hstdb, "/etc/resolv.conf", 1); + register_file (cb, servdb, "/etc/services", 0); + register_file (cb, netgrdb, "/etc/netgroup", 0); } #endif