From patchwork Mon Jul 3 12:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 72006 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 9E2D3386076B for ; Mon, 3 Jul 2023 12:44:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E2D3386076B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688388284; bh=zEFLaTVhgMaYjSawAvMusR5Ngdl7s7Wqy2rcj1wOYTI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Psqy+cb+FI4DrzXqZGL/xACs6IVBR6TwaAFk0HxhPZv/VFn3O7GdMveM4+Oj8y0bW /QeBaInSvMU/XPHUYUPmWWu50Jk8DwFPZE5ZADS56xUaQgAAdF86dmyjsrpHKn6D2h ZmYjrCYyXM9QGTgKse2RwE/PP1T+ztHdfS+oOB/c= 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 ESMTPS id AD2B4385696F for ; Mon, 3 Jul 2023 12:44:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD2B4385696F Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-e1jHUkwpN2K8Pa9GUQesaQ-1; Mon, 03 Jul 2023 08:43:55 -0400 X-MC-Unique: e1jHUkwpN2K8Pa9GUQesaQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA03D1C4FD87; Mon, 3 Jul 2023 12:43:54 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6320714682F9; Mon, 3 Jul 2023 12:43:53 +0000 (UTC) To: libc-alpha@sourceware.org Cc: "Hiroaki.Fuse@sony.com" , libc-stable@sourceware.org Subject: [PATCH] nscd: Move declarations used in the library out of Date: Mon, 03 Jul 2023 14:43:52 +0200 Message-ID: <87ilb1yxkn.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, TXREP, T_SCC_BODY_TEXT_LINE, T_SPF_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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" Installed the shared header as include/nscd.h. Rename the remaining header with the nscd-internal declarations from nscd/nscd.h to nscd/nscdP.h. This makes it clear that the library does not depend on include/programs/xmalloc.h. Tested on i686-linux-gnu and x86_64-linux-gnu. Built with build-many-glibcs.py. --- include/nscd.h | 99 +++++++++++++++++++++++++++++ nscd/aicache.c | 2 +- nscd/cache.c | 2 +- nscd/cachedumper.c | 2 +- nscd/connections.c | 2 +- nscd/dbg_log.c | 2 +- nscd/grpcache.c | 2 +- nscd/hstcache.c | 2 +- nscd/initgrcache.c | 2 +- nscd/mem.c | 2 +- nscd/netgroupcache.c | 2 +- nscd/nscd-client.h | 2 +- nscd/{nscd.h => nscdP.h} | 83 ++---------------------- nscd/nscd_conf.c | 2 +- nscd/nscd_setup_thread.c | 2 +- nscd/pwdcache.c | 2 +- nscd/selinux.h | 2 +- nscd/servicescache.c | 2 +- nss/nss_db/db-init.c | 2 +- nss/nss_files/files-init.c | 2 +- nss/nss_module.c | 2 +- sysdeps/unix/sysv/linux/nscd_setup_thread.c | 2 +- 22 files changed, 124 insertions(+), 98 deletions(-) base-commit: e18c293af0ece38921ad71fbd76ff8049c3b2d67 diff --git a/include/nscd.h b/include/nscd.h new file mode 100644 index 0000000000..109e3ab800 --- /dev/null +++ b/include/nscd.h @@ -0,0 +1,99 @@ +/* Private interface between sncd and NSS service modules. + Copyright (c) 2011-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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. + + The GNU C 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 the GNU C Library; if not, see + . */ + +#ifndef NSCD_H +#define NSCD_H + +#include +#include +#include + +/* Handle databases. */ +typedef enum +{ + pwddb, + grpdb, + hstdb, + servdb, + netgrdb, + lastdb +} dbtype; + +/* Records the file registered per database that when changed + or modified requires invalidating the database. */ +struct traced_file +{ + /* Tracks the last modified time of the traced file. */ + __time64_t mtime; + /* Support multiple registered files per database. */ + struct traced_file *next; + int call_res_init; + /* Requires Inotify support to do anything useful. */ +#define TRACED_FILE 0 +#define TRACED_DIR 1 + int inotify_descr[2]; +# ifndef PATH_MAX +# define PATH_MAX 1024 +# endif + /* The parent directory is used to scan for creation/deletion. */ + char dname[PATH_MAX]; + /* Just the name of the file with no directory component. */ + char *sfname; + /* The full-path name of the registered file. */ + char fname[]; +}; + +/* Initialize a `struct traced_file`. As input we need the name + of the file, and if invalidation requires calling res_init. + If CRINIT is 1 then res_init will be called after invalidation + or if the traced file is changed in any way, otherwise it will + not. */ +static inline void +init_traced_file(struct traced_file *file, const char *fname, int crinit) +{ + char *dname; + file->mtime = 0; + file->inotify_descr[TRACED_FILE] = -1; + file->inotify_descr[TRACED_DIR] = -1; + strcpy (file->fname, fname); + /* Compute the parent directory name and store a copy. The copy makes + it much faster to add/remove watches while nscd is running instead + of computing this over and over again in a temp buffer. */ + file->dname[0] = '\0'; + dname = strrchr (fname, '/'); + if (dname != NULL) + { + size_t len = (size_t)(dname - fname); + if (len > sizeof (file->dname)) + abort (); + memcpy (file->dname, file->fname, len); + file->dname[len] = '\0'; + } + /* The basename is the name just after the last forward slash. */ + file->sfname = &dname[1]; + file->call_res_init = crinit; +} + +#define define_traced_file(id, filename) \ +static union \ +{ \ + struct traced_file file; \ + char buf[sizeof (struct traced_file) + sizeof (filename)]; \ +} id##_traced_file; + +#endif /* NSCD_H */ diff --git a/nscd/aicache.c b/nscd/aicache.c index 96f699c216..1967402a90 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -29,7 +29,7 @@ #include #include "dbg_log.h" -#include "nscd.h" +#include "nscdP.h" static const ai_response_header notfound = diff --git a/nscd/cache.c b/nscd/cache.c index b4b54d82bb..7071855774 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -30,7 +30,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" diff --git a/nscd/cachedumper.c b/nscd/cachedumper.c index a197c081ef..68f9af49f7 100644 --- a/nscd/cachedumper.c +++ b/nscd/cachedumper.c @@ -28,7 +28,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" static void *the_cache; diff --git a/nscd/connections.c b/nscd/connections.c index a405a44a9b..92b29e5148 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -49,7 +49,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" #include "selinux.h" #include diff --git a/nscd/dbg_log.c b/nscd/dbg_log.c index d31e79ceb3..d1e2523356 100644 --- a/nscd/dbg_log.c +++ b/nscd/dbg_log.c @@ -20,7 +20,7 @@ #include #include #include "dbg_log.h" -#include "nscd.h" +#include "nscdP.h" /* if in debug mode and we have a debug file, we write the messages to it, if in debug mode and no debug file, we write the messages to stderr, diff --git a/nscd/grpcache.c b/nscd/grpcache.c index cdd1071970..93a9c9e7a0 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -32,7 +32,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" /* This is the standard reply in case the service is disabled. */ diff --git a/nscd/hstcache.c b/nscd/hstcache.c index bd289b4628..a979cff983 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -35,7 +35,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index be44951bd6..1b9bee5711 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -27,7 +27,7 @@ #include #include "dbg_log.h" -#include "nscd.h" +#include "nscdP.h" #include "../nss/nsswitch.h" diff --git a/nscd/mem.c b/nscd/mem.c index 50f8162609..07ffcb542d 100644 --- a/nscd/mem.c +++ b/nscd/mem.c @@ -30,7 +30,7 @@ #include #include "dbg_log.h" -#include "nscd.h" +#include "nscdP.h" static int diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c index 06b7d7b6ca..9b317a38cd 100644 --- a/nscd/netgroupcache.c +++ b/nscd/netgroupcache.c @@ -25,7 +25,7 @@ #include #include "../inet/netgroup.h" -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" #include diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h index 5588ade982..9126fc83c2 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -450,4 +450,4 @@ extern ssize_t writeall (int fd, const void *buf, size_t len) extern uint32_t __nscd_get_nl_timestamp (void) attribute_hidden; -#endif /* nscd.h */ +#endif /* nscd-client.h */ diff --git a/nscd/nscd.h b/nscd/nscdP.h similarity index 82% rename from nscd/nscd.h rename to nscd/nscdP.h index 04f82fc0b0..7d5f6e2011 100644 --- a/nscd/nscd.h +++ b/nscd/nscdP.h @@ -15,32 +15,21 @@ License along with the GNU C Library; if not, see . */ -#ifndef _NSCD_H -#define _NSCD_H 1 +#ifndef _NSCDP_H +#define _NSCDP_H 1 #include #include #include #include +#include + /* The declarations for the request and response types are in the file "nscd-client.h", which should contain everything needed by client functions. */ #include "nscd-client.h" - -/* Handle databases. */ -typedef enum -{ - pwddb, - grpdb, - hstdb, - servdb, - netgrdb, - lastdb -} dbtype; - - /* Default limit on the number of times a value gets reloaded without being used in the meantime. NSCD does not throw a value out as soon as it times out. It tries to reload the value from the @@ -60,68 +49,6 @@ typedef enum 80% of the thread stack size. */ #define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10) -/* Records the file registered per database that when changed - or modified requires invalidating the database. */ -struct traced_file -{ - /* Tracks the last modified time of the traced file. */ - __time64_t mtime; - /* Support multiple registered files per database. */ - struct traced_file *next; - int call_res_init; - /* Requires Inotify support to do anything useful. */ -#define TRACED_FILE 0 -#define TRACED_DIR 1 - int inotify_descr[2]; -# ifndef PATH_MAX -# define PATH_MAX 1024 -# endif - /* The parent directory is used to scan for creation/deletion. */ - char dname[PATH_MAX]; - /* Just the name of the file with no directory component. */ - char *sfname; - /* The full-path name of the registered file. */ - char fname[]; -}; - -/* Initialize a `struct traced_file`. As input we need the name - of the file, and if invalidation requires calling res_init. - If CRINIT is 1 then res_init will be called after invalidation - or if the traced file is changed in any way, otherwise it will - not. */ -static inline void -init_traced_file(struct traced_file *file, const char *fname, int crinit) -{ - char *dname; - file->mtime = 0; - file->inotify_descr[TRACED_FILE] = -1; - file->inotify_descr[TRACED_DIR] = -1; - strcpy (file->fname, fname); - /* Compute the parent directory name and store a copy. The copy makes - it much faster to add/remove watches while nscd is running instead - of computing this over and over again in a temp buffer. */ - file->dname[0] = '\0'; - dname = strrchr (fname, '/'); - if (dname != NULL) - { - size_t len = (size_t)(dname - fname); - if (len > sizeof (file->dname)) - abort (); - memcpy (file->dname, file->fname, len); - file->dname[len] = '\0'; - } - /* The basename is the name just after the last forward slash. */ - file->sfname = &dname[1]; - file->call_res_init = crinit; -} - -#define define_traced_file(id, filename) \ -static union \ -{ \ - struct traced_file file; \ - char buf[sizeof (struct traced_file) + sizeof (filename)]; \ -} id##_traced_file; - /* Structure describing dynamic part of one database. */ struct database_dyn { @@ -375,4 +302,4 @@ extern void nscd_print_cache (const char *name); while (__result == EINTR); \ __result; })) -#endif /* nscd.h */ +#endif /* nscdP.h */ diff --git a/nscd/nscd_conf.c b/nscd/nscd_conf.c index ead13e99b8..717ad8b425 100644 --- a/nscd/nscd_conf.c +++ b/nscd/nscd_conf.c @@ -29,7 +29,7 @@ #include #include "dbg_log.h" -#include "nscd.h" +#include "nscdP.h" /* Names of the databases. */ diff --git a/nscd/nscd_setup_thread.c b/nscd/nscd_setup_thread.c index 5d6eff7a59..d33cd1069f 100644 --- a/nscd/nscd_setup_thread.c +++ b/nscd/nscd_setup_thread.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . */ -#include +#include int diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index e1b579de6b..e89b93fb07 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -32,7 +32,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" /* This is the standard reply in case the service is disabled. */ diff --git a/nscd/selinux.h b/nscd/selinux.h index 3f075b5533..b505654f7f 100644 --- a/nscd/selinux.h +++ b/nscd/selinux.h @@ -19,7 +19,7 @@ #ifndef _SELINUX_H #define _SELINUX_H 1 -#include "nscd.h" +#include "nscdP.h" #ifdef HAVE_LIBCAP # include #endif diff --git a/nscd/servicescache.c b/nscd/servicescache.c index 2202679500..68663bb1af 100644 --- a/nscd/servicescache.c +++ b/nscd/servicescache.c @@ -25,7 +25,7 @@ #include #include -#include "nscd.h" +#include "nscdP.h" #include "dbg_log.h" diff --git a/nss/nss_db/db-init.c b/nss/nss_db/db-init.c index bd79826cab..850e8c5fb4 100644 --- a/nss/nss_db/db-init.c +++ b/nss/nss_db/db-init.c @@ -19,7 +19,7 @@ #ifdef USE_NSCD #include -#include +#include #include #include "nss_db.h" diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c index d5c2795b30..541ad65ffe 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -19,7 +19,7 @@ #ifdef USE_NSCD #include -#include +#include #include #include diff --git a/nss/nss_module.c b/nss/nss_module.c index 0104f88974..934ff4a968 100644 --- a/nss/nss_module.c +++ b/nss/nss_module.c @@ -17,7 +17,7 @@ . */ #include -#include +#include #include #include diff --git a/sysdeps/unix/sysv/linux/nscd_setup_thread.c b/sysdeps/unix/sysv/linux/nscd_setup_thread.c index cf1a56e005..76d9fad10f 100644 --- a/sysdeps/unix/sysv/linux/nscd_setup_thread.c +++ b/sysdeps/unix/sysv/linux/nscd_setup_thread.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include