summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMarius Bakke <marius@gnu.org>2022-09-16 03:27:09 +0200
committerMarius Bakke <marius@gnu.org>2022-09-16 22:41:22 +0200
commit6703ff4d3bfba7ab9d35c739df8e1b983505afa9 (patch)
tree9e363c2245830cc6ff7b8e5d59b3c2b928e81be9 /gnu
parent887e83997e4c3fdab20cd3d2aec6ae3e66850669 (diff)
gnu: glibc-for-bootstrap: Remove obsolete patch.
* gnu/packages/patches/glibc-static-nss.patch: Delete file. * gnu/local.mk (dist_patch_DATA): Adjust accordingly. * gnu/packages/make-bootstrap.scm (glibc-for-bootstrap)[source](patches): Remove it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/packages/make-bootstrap.scm3
-rw-r--r--gnu/packages/patches/glibc-static-nss.patch1244
3 files changed, 1 insertions, 1247 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index a1e8a0f3892..1f3169bb1ad 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1198,7 +1198,6 @@ dist_patch_DATA = \
1198 %D%/packages/patches/glibc-versioned-locpath.patch \ 1198 %D%/packages/patches/glibc-versioned-locpath.patch \
1199 %D%/packages/patches/glibc-2.29-git-updates.patch \ 1199 %D%/packages/patches/glibc-2.29-git-updates.patch \
1200 %D%/packages/patches/glibc-2.29-supported-locales.patch \ 1200 %D%/packages/patches/glibc-2.29-supported-locales.patch \
1201 %D%/packages/patches/glibc-static-nss.patch \
1202 %D%/packages/patches/glibc-supported-locales.patch \ 1201 %D%/packages/patches/glibc-supported-locales.patch \
1203 %D%/packages/patches/gmp-arm-asm-nothumb.patch \ 1202 %D%/packages/patches/gmp-arm-asm-nothumb.patch \
1204 %D%/packages/patches/gmp-faulty-test.patch \ 1203 %D%/packages/patches/gmp-faulty-test.patch \
diff --git a/gnu/packages/make-bootstrap.scm b/gnu/packages/make-bootstrap.scm
index 326ddf561e2..977adbba190 100644
--- a/gnu/packages/make-bootstrap.scm
+++ b/gnu/packages/make-bootstrap.scm
@@ -75,8 +75,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
75 (inherit base) 75 (inherit base)
76 (source (origin (inherit (package-source base)) 76 (source (origin (inherit (package-source base))
77 (patches (append (search-patches 77 (patches (append (search-patches
78 "glibc-bootstrap-system.patch" 78 "glibc-bootstrap-system.patch")
79 "glibc-static-nss.patch")
80 (origin-patches (package-source base)))))) 79 (origin-patches (package-source base))))))
81 (arguments 80 (arguments
82 (substitute-keyword-arguments (package-arguments base) 81 (substitute-keyword-arguments (package-arguments base)
diff --git a/gnu/packages/patches/glibc-static-nss.patch b/gnu/packages/patches/glibc-static-nss.patch
deleted file mode 100644
index 1a9db616cc2..00000000000
--- a/gnu/packages/patches/glibc-static-nss.patch
+++ /dev/null
@@ -1,1244 +0,0 @@
1This patch reinstates support for static NSS, which glibc 2.33 broke:
2
3 https://sourceware.org/bugzilla/show_bug.cgi?id=27959
4
5Patch obtained by running:
6
7 git diff f0c28504a9877be5da3ed1215f2da2d5914bbb0b..f9c8b11ed7726b858cd7b7cea0d3d7c5233d78cf
8 git diff 5e1ce61e3e71fb7ffe53f58fe96e67cb15f94854{^,}
9 git diff 135425a1dd50cbe2b9db0628d6c2b36c7889f30b{^,}
10
11It corresponds to these changes:
12
13 f9c8b11ed7 * nss: Access nss_files through direct references
14 6212bb67f4 * nss_files: Move into libc
15 36861a968a * nss_files: Add generic code for set*ent, end*ent and file open
16 f0c28504a9 * nss_files: Allocate nscd file registration data on the heap
17 5e1ce61e3e * nss: Fix NSS_DECLARE_MODULE_FUNCTIONS handling of _nss_*_endnetgrent
18 135425a1dd * nss: Fix build error with --disable-nscd
19
20... plus a manual fix in 'files-network.c' to address this compilation error:
21
22 nss_files/files-network.c: In function ‘_nss_files_parse_netent’:
23 nss_files/files-network.c:72:20: error: implicit declaration of function ‘__inet_network’; did you mean ‘inet_network’? [-Werror=implicit-function-declaration]
24 72 | result->n_net = __inet_network (addr);
25 | ^~~~~~~~~~~~~~
26 nss_files/files-parse.c:106:3: note: in definition of macro ‘LINE_PARSER’
27 106 | BODY; \
28 | ^~~~
29
30diff --git a/include/libc-symbols.h b/include/libc-symbols.h
31index 127ea656c2..d41ecf4384 100644
32--- a/include/libc-symbols.h
33+++ b/include/libc-symbols.h
34@@ -798,29 +798,6 @@ for linking")
35 # define libdl_hidden_data_ver(local, name)
36 #endif
37
38-#if IS_IN (libnss_files)
39-# define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
40-# define libnss_files_hidden_tls_proto(name, attrs...) \
41- hidden_tls_proto (name, ##attrs)
42-# define libnss_files_hidden_def(name) hidden_def (name)
43-# define libnss_files_hidden_weak(name) hidden_weak (name)
44-# define libnss_files_hidden_ver(local, name) hidden_ver (local, name)
45-# define libnss_files_hidden_data_def(name) hidden_data_def (name)
46-# define libnss_files_hidden_tls_def(name) hidden_tls_def (name)
47-# define libnss_files_hidden_data_weak(name) hidden_data_weak (name)
48-# define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name)
49-#else
50-# define libnss_files_hidden_proto(name, attrs...)
51-# define libnss_files_hidden_tls_proto(name, attrs...)
52-# define libnss_files_hidden_def(name)
53-# define libnss_files_hidden_weak(name)
54-# define libnss_files_hidden_ver(local, name)
55-# define libnss_files_hidden_data_def(name)
56-# define libnss_files_hidden_tls_def(name)
57-# define libnss_files_hidden_data_weak(name)
58-# define libnss_files_hidden_data_ver(local, name)
59-#endif
60-
61 #if IS_IN (libnsl)
62 # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
63 # define libnsl_hidden_tls_proto(name, attrs...) \
64diff --git a/include/netdb.h b/include/netdb.h
65index 82e102ff76..4dcdbb8cd4 100644
66--- a/include/netdb.h
67+++ b/include/netdb.h
68@@ -217,7 +217,7 @@ extern enum nss_status _nss_netgroup_parseline (char **cursor,
69 struct __netgrent *result,
70 char *buffer, size_t buflen,
71 int *errnop);
72-libnss_files_hidden_proto (_nss_netgroup_parseline)
73+libc_hidden_proto (_nss_netgroup_parseline)
74
75 #define DECLARE_NSS_PROTOTYPES(service) \
76 extern enum nss_status _nss_ ## service ## _setprotoent (int); \
77diff --git a/include/nss_files.h b/include/nss_files.h
78index 6a0dcdb85b..6190cac6be 100644
79--- a/include/nss_files.h
80+++ b/include/nss_files.h
81@@ -19,7 +19,11 @@
82 #ifndef _NSS_FILES_H
83 #define _NSS_FILES_H
84
85+#include <nss.h>
86 #include <stdio.h>
87+#if IS_IN (libc)
88+#include <libc-lock.h>
89+#endif
90
91 /* Open PATH for reading, as a data source for nss_files. */
92 FILE *__nss_files_fopen (const char *path);
93@@ -47,6 +51,63 @@ int __nss_readline_seek (FILE *fp, off64_t offset) attribute_hidden;
94 int __nss_parse_line_result (FILE *fp, off64_t offset, int parse_line_result);
95 libc_hidden_proto (__nss_parse_line_result)
96
97+/* Per-file data. Used by the *ent functions that need to preserve
98+ state across calls. */
99+struct nss_files_per_file_data
100+{
101+ FILE *stream;
102+#if IS_IN (libc)
103+ /* The size of locks changes between libc and nss_files, so this
104+ member must be last and is only available in libc. */
105+ __libc_lock_define (, lock);
106+#endif
107+};
108+
109+/* File index for __nss_files_data_get. */
110+enum nss_files_file
111+ {
112+ nss_file_aliasent,
113+ nss_file_etherent,
114+ nss_file_grent,
115+ nss_file_hostent,
116+ nss_file_netent,
117+ nss_file_protoent,
118+ nss_file_pwent,
119+ nss_file_rpcent,
120+ nss_file_servent,
121+ nss_file_sgent,
122+ nss_file_spent,
123+
124+ nss_file_count
125+ };
126+
127+/* Obtains a pointer to the per-file data for FILE, which is written
128+ to *PDATA, and tries to open the file at PATH for it. On success,
129+ returns NSS_STATUS_SUCCESS, and the caller must later call
130+ __nss_files_data_put. On failure, NSS_STATUS_TRYAGAIN is returned,
131+ and *ERRNOP and *HERRNOP are updated if these pointers are not
132+ null. */
133+enum nss_status __nss_files_data_open (struct nss_files_per_file_data **pdata,
134+ enum nss_files_file file,
135+ const char *path,
136+ int *errnop, int *herrnop);
137+libc_hidden_proto (__nss_files_data_open)
138+
139+/* Unlock the per-file data, previously obtained by
140+ __nss_files_data_open. */
141+void __nss_files_data_put (struct nss_files_per_file_data *data);
142+libc_hidden_proto (__nss_files_data_put)
143+
144+/* Performs the set*ent operation for FILE. PATH is the file to
145+ open. */
146+enum nss_status __nss_files_data_setent (enum nss_files_file file,
147+ const char *path);
148+libc_hidden_proto (__nss_files_data_setent)
149+
150+/* Performs the end*ent operation for FILE. */
151+enum nss_status __nss_files_data_endent (enum nss_files_file file);
152+libc_hidden_proto (__nss_files_data_endent)
153+
154 struct parser_data;
155
156 /* Instances of the parse_line function from
157@@ -64,16 +125,25 @@ extern nss_files_parse_line _nss_files_parse_servent;
158 extern nss_files_parse_line _nss_files_parse_sgent;
159 extern nss_files_parse_line _nss_files_parse_spent;
160
161-libnss_files_hidden_proto (_nss_files_parse_etherent)
162+libc_hidden_proto (_nss_files_parse_etherent)
163 libc_hidden_proto (_nss_files_parse_grent)
164-libnss_files_hidden_proto (_nss_files_parse_netent)
165-libnss_files_hidden_proto (_nss_files_parse_protoent)
166+libc_hidden_proto (_nss_files_parse_netent)
167+libc_hidden_proto (_nss_files_parse_protoent)
168 libc_hidden_proto (_nss_files_parse_pwent)
169-libnss_files_hidden_proto (_nss_files_parse_rpcent)
170-libnss_files_hidden_proto (_nss_files_parse_servent)
171+libc_hidden_proto (_nss_files_parse_rpcent)
172+libc_hidden_proto (_nss_files_parse_servent)
173 libc_hidden_proto (_nss_files_parse_sgent)
174 libc_hidden_proto (_nss_files_parse_spent)
175
176+NSS_DECLARE_MODULE_FUNCTIONS (files)
177+#undef DEFINE_NSS_FUNCTION
178+#define DEFINE_NSS_FUNCTION(x) libc_hidden_proto (_nss_files_##x)
179+#include <nss/function.def>
180+#undef DEFINE_NSS_FUNCTION
181+
182+void _nss_files_init (void (*cb) (size_t, struct traced_file *));
183+libc_hidden_proto (_nss_files_init)
184+
185 /* Generic implementation of fget*ent_r. Reads lines from FP until
186 EOF or a successful parse into *RESULT using PARSER. Returns 0 on
187 success, ENOENT on EOF, ERANGE on too-small buffer. */
188diff --git a/nss/Makefile b/nss/Makefile
189index 9682a31e20..63a386af18 100644
190--- a/nss/Makefile
191+++ b/nss/Makefile
192@@ -31,7 +31,8 @@ routines = nsswitch getnssent getnssent_r digits_dots \
193 compat-lookup nss_hash nss_files_fopen \
194 nss_readline nss_parse_line_result \
195 nss_fgetent_r nss_module nss_action \
196- nss_action_parse nss_database
197+ nss_action_parse nss_database nss_files_data \
198+ nss_files_functions
199
200 # These are the databases that go through nss dispatch.
201 # Caution: if you add a database here, you must add its real name
202@@ -98,9 +99,11 @@ subdir-dirs = $(services:%=nss_%)
203 vpath %.c $(subdir-dirs) ../locale/programs ../intl
204
205
206-libnss_files-routines := $(addprefix files-, \
207- $(filter-out key, $(databases))) \
208- files-initgroups files-init
209+routines += \
210+ $(addprefix files-, $(filter-out key, $(databases))) \
211+ files-init \
212+ files-initgroups \
213+ # routines
214
215 libnss_db-dbs := $(addprefix db-,\
216 $(filter-out hosts network key alias,\
217@@ -116,12 +119,9 @@ libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups) \
218 install-others += $(inst_vardbdir)/Makefile
219
220 # Build static module into libc if requested
221-libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
222 libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
223 libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes))
224 ifeq ($(build-static-nss),yes)
225-routines += $(libnss_files-routines)
226-static-only-routines += $(libnss_files-routines)
227 tests-static += tst-nss-static
228 endif
229 extra-test-objs += nss_test1.os nss_test2.os
230@@ -138,8 +138,6 @@ libnss-libc = $(common-objpfx)linkobj/libc.so
231 # for new links:
232 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
233
234-$(objpfx)libnss_db.so: $(objpfx)libnss_files.so
235-
236 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
237 @rm -f $@.new
238 (echo '#define EXTERN_PARSER';\
239diff --git a/nss/Versions b/nss/Versions
240index fdddea104c..e551524aa9 100644
241--- a/nss/Versions
242+++ b/nss/Versions
243@@ -19,11 +19,12 @@ libc {
244 __nss_services_lookup2; __nss_next2; __nss_lookup;
245 __nss_hash; __nss_database_get;
246 __nss_files_fopen; __nss_readline; __nss_parse_line_result;
247- }
248-}
249+ __nss_files_data_endent;
250+ __nss_files_data_open;
251+ __nss_files_data_put;
252+ __nss_files_data_setent;
253
254-libnss_files {
255- GLIBC_PRIVATE {
256+ # Routines formerly in libnss_files.so.2.
257 _nss_files_setaliasent;
258 _nss_files_endaliasent;
259 _nss_files_getaliasbyname_r;
260@@ -109,6 +110,14 @@ libnss_files {
261 }
262 }
263
264+libnss_files {
265+ GLIBC_PRIVATE {
266+ # Keep a version node (with a synthesized local: * directive) so that
267+ # __bss_* symbols are hidden on targets that need it.
268+ __libnss_files_version_placeholder;
269+ }
270+}
271+
272 libnss_db {
273 GLIBC_PRIVATE {
274 _nss_db_setetherent;
275diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
276index b4b989d9bb..c158a891bd 100644
277--- a/nss/nss_files/files-XXX.c
278+++ b/nss/nss_files/files-XXX.c
279@@ -45,10 +45,12 @@
280 # include <netdb.h>
281 # define H_ERRNO_PROTO , int *herrnop
282 # define H_ERRNO_ARG , herrnop
283+# define H_ERRNO_ARG_OR_NULL herrnop
284 # define H_ERRNO_SET(val) (*herrnop = (val))
285 #else
286 # define H_ERRNO_PROTO
287 # define H_ERRNO_ARG
288+# define H_ERRNO_ARG_OR_NULL NULL
289 # define H_ERRNO_SET(val) ((void) 0)
290 #endif
291
292@@ -58,15 +60,11 @@
293 # define EXTRA_ARGS_VALUE
294 #endif
295
296-/* Locks the static variables in this file. */
297-__libc_lock_define_initialized (static, lock)
298
299 /* Maintenance of the stream open on the database file. For getXXent
300 operations the stream needs to be held open across calls, the other
301 getXXbyYY operations all use their own stream. */
302
303-static FILE *stream;
304-
305 /* Open database file if not already opened. */
306 static enum nss_status
307 internal_setent (FILE **stream)
308@@ -91,42 +89,16 @@ internal_setent (FILE **stream)
309 enum nss_status
310 CONCAT(_nss_files_set,ENTNAME) (int stayopen)
311 {
312- enum nss_status status;
313-
314- __libc_lock_lock (lock);
315-
316- status = internal_setent (&stream);
317-
318- __libc_lock_unlock (lock);
319-
320- return status;
321+ return __nss_files_data_setent (CONCAT (nss_file_, ENTNAME), DATAFILE);
322 }
323+libc_hidden_def (CONCAT (_nss_files_set,ENTNAME))
324
325-
326-/* Close the database file. */
327-static void
328-internal_endent (FILE **stream)
329-{
330- if (*stream != NULL)
331- {
332- fclose (*stream);
333- *stream = NULL;
334- }
335-}
336-
337-
338-/* Thread-safe, exported version of that. */
339 enum nss_status
340 CONCAT(_nss_files_end,ENTNAME) (void)
341 {
342- __libc_lock_lock (lock);
343-
344- internal_endent (&stream);
345-
346- __libc_lock_unlock (lock);
347-
348- return NSS_STATUS_SUCCESS;
349+ return __nss_files_data_endent (CONCAT (nss_file_, ENTNAME));
350 }
351+libc_hidden_def (CONCAT (_nss_files_end,ENTNAME))
352
353
354 /* Parsing the database file into `struct STRUCTURE' data structures. */
355@@ -194,28 +166,22 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer,
356 size_t buflen, int *errnop H_ERRNO_PROTO)
357 {
358 /* Return next entry in host file. */
359- enum nss_status status = NSS_STATUS_SUCCESS;
360-
361- __libc_lock_lock (lock);
362
363- /* Be prepared that the set*ent function was not called before. */
364- if (stream == NULL)
365- {
366- int save_errno = errno;
367-
368- status = internal_setent (&stream);
369-
370- __set_errno (save_errno);
371- }
372-
373- if (status == NSS_STATUS_SUCCESS)
374- status = internal_getent (stream, result, buffer, buflen, errnop
375- H_ERRNO_ARG EXTRA_ARGS_VALUE);
376+ struct nss_files_per_file_data *data;
377+ enum nss_status status = __nss_files_data_open (&data,
378+ CONCAT (nss_file_, ENTNAME),
379+ DATAFILE,
380+ errnop, H_ERRNO_ARG_OR_NULL);
381+ if (status != NSS_STATUS_SUCCESS)
382+ return status;
383
384- __libc_lock_unlock (lock);
385+ status = internal_getent (data->stream, result, buffer, buflen, errnop
386+ H_ERRNO_ARG EXTRA_ARGS_VALUE);
387
388+ __nss_files_data_put (data);
389 return status;
390 }
391+libc_hidden_def (CONCAT (_nss_files_get,ENTNAME_r))
392
393 /* Macro for defining lookup functions for this file-based database.
394
395@@ -248,8 +214,9 @@ _nss_files_get##name##_r (proto, \
396 == NSS_STATUS_SUCCESS) \
397 { break_if_match } \
398 \
399- internal_endent (&stream); \
400+ fclose (stream); \
401 } \
402 \
403 return status; \
404-}
405+} \
406+libc_hidden_def (_nss_files_get##name##_r)
407diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
408index 30971bfe56..8c6e176ff6 100644
409--- a/nss/nss_files/files-alias.c
410+++ b/nss/nss_files/files-alias.c
411@@ -31,18 +31,11 @@
412 #include "nsswitch.h"
413 #include <nss_files.h>
414
415-NSS_DECLARE_MODULE_FUNCTIONS (files)
416-
417-/* Locks the static variables in this file. */
418-__libc_lock_define_initialized (static, lock)
419
420 /* Maintenance of the stream open on the database file. For getXXent
421 operations the stream needs to be held open across calls, the other
422 getXXbyYY operations all use their own stream. */
423
424-static FILE *stream;
425-
426-
427 static enum nss_status
428 internal_setent (FILE **stream)
429 {
430@@ -66,42 +59,16 @@ internal_setent (FILE **stream)
431 enum nss_status
432 _nss_files_setaliasent (void)
433 {
434- enum nss_status status;
435-
436- __libc_lock_lock (lock);
437-
438- status = internal_setent (&stream);
439-
440- __libc_lock_unlock (lock);
441-
442- return status;
443+ return __nss_files_data_setent (nss_file_aliasent, "/etc/aliases");
444 }
445+libc_hidden_def (_nss_files_setaliasent)
446
447-
448-/* Close the database file. */
449-static void
450-internal_endent (FILE **stream)
451-{
452- if (*stream != NULL)
453- {
454- fclose (*stream);
455- *stream = NULL;
456- }
457-}
458-
459-
460-/* Thread-safe, exported version of that. */
461 enum nss_status
462 _nss_files_endaliasent (void)
463 {
464- __libc_lock_lock (lock);
465-
466- internal_endent (&stream);
467-
468- __libc_lock_unlock (lock);
469-
470- return NSS_STATUS_SUCCESS;
471+ return __nss_files_data_endent (nss_file_aliasent);
472 }
473+libc_hidden_def (_nss_files_endaliasent)
474
475 /* Parsing the database file into `struct aliasent' data structures. */
476 static enum nss_status
477@@ -131,7 +98,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
478 /* Read the first line. It must contain the alias name and
479 possibly some alias names. */
480 first_unused[room_left - 1] = '\xff';
481- line = fgets_unlocked (first_unused, room_left, stream);
482+ line = __fgets_unlocked (first_unused, room_left, stream);
483 if (line == NULL)
484 /* Nothing to read. */
485 break;
486@@ -220,7 +187,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
487 /* If the file does not exist we simply ignore
488 the statement. */
489 if (listfile != NULL
490- && (old_line = strdup (line)) != NULL)
491+ && (old_line = __strdup (line)) != NULL)
492 {
493 while (! feof_unlocked (listfile))
494 {
495@@ -232,8 +199,8 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
496 }
497
498 first_unused[room_left - 1] = '\xff';
499- line = fgets_unlocked (first_unused, room_left,
500- listfile);
501+ line = __fgets_unlocked (first_unused, room_left,
502+ listfile);
503 if (line == NULL)
504 break;
505 if (first_unused[room_left - 1] != '\xff')
506@@ -335,7 +302,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result,
507 /* The just read character is a white space and so
508 can be ignored. */
509 first_unused[room_left - 1] = '\xff';
510- line = fgets_unlocked (first_unused, room_left, stream);
511+ line = __fgets_unlocked (first_unused, room_left, stream);
512 if (line == NULL)
513 {
514 /* Continuation line without any data and
515@@ -369,29 +336,25 @@ _nss_files_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen,
516 int *errnop)
517 {
518 /* Return next entry in host file. */
519- enum nss_status status = NSS_STATUS_SUCCESS;
520
521- __libc_lock_lock (lock);
522-
523- /* Be prepared that the set*ent function was not called before. */
524- if (stream == NULL)
525- status = internal_setent (&stream);
526-
527- if (status == NSS_STATUS_SUCCESS)
528- {
529- result->alias_local = 1;
530+ struct nss_files_per_file_data *data;
531+ enum nss_status status = __nss_files_data_open (&data, nss_file_aliasent,
532+ "/etc/aliases", errnop, NULL);
533+ if (status != NSS_STATUS_SUCCESS)
534+ return status;
535
536- /* Read lines until we get a definite result. */
537- do
538- status = get_next_alias (stream, NULL, result, buffer, buflen, errnop);
539- while (status == NSS_STATUS_RETURN);
540- }
541+ result->alias_local = 1;
542
543- __libc_lock_unlock (lock);
544+ /* Read lines until we get a definite result. */
545+ do
546+ status = get_next_alias (data->stream, NULL, result, buffer, buflen,
547+ errnop);
548+ while (status == NSS_STATUS_RETURN);
549
550+ __nss_files_data_put (data);
551 return status;
552 }
553-
554+libc_hidden_def (_nss_files_getaliasent_r)
555
556 enum nss_status
557 _nss_files_getaliasbyname_r (const char *name, struct aliasent *result,
558@@ -418,9 +381,10 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result,
559 do
560 status = get_next_alias (stream, name, result, buffer, buflen, errnop);
561 while (status == NSS_STATUS_RETURN);
562- }
563
564- internal_endent (&stream);
565+ fclose (stream);
566+ }
567
568 return status;
569 }
570+libc_hidden_def (_nss_files_getaliasbyname_r)
571diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c
572index 2fe7f81e4b..7c2c2b9833 100644
573--- a/nss/nss_files/files-ethers.c
574+++ b/nss/nss_files/files-ethers.c
575@@ -20,8 +20,6 @@
576 #include <netinet/if_ether.h>
577 #include <nss.h>
578
579-NSS_DECLARE_MODULE_FUNCTIONS (files)
580-
581 struct etherent_data {};
582
583 #define ENTNAME etherent
584diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c
585index 49be38e8b1..a716d948e2 100644
586--- a/nss/nss_files/files-grp.c
587+++ b/nss/nss_files/files-grp.c
588@@ -19,8 +19,6 @@
589 #include <grp.h>
590 #include <nss.h>
591
592-NSS_DECLARE_MODULE_FUNCTIONS (files)
593-
594 #define STRUCTURE group
595 #define ENTNAME grent
596 #define DATABASE "group"
597diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
598index 2b47ec3e53..d54d91d038 100644
599--- a/nss/nss_files/files-hosts.c
600+++ b/nss/nss_files/files-hosts.c
601@@ -26,8 +26,6 @@
602 #include <alloc_buffer.h>
603 #include <nss.h>
604
605-NSS_DECLARE_MODULE_FUNCTIONS (files)
606-
607 /* Get implementation for some internal functions. */
608 #include "../resolv/res_hconf.h"
609
610@@ -57,12 +55,13 @@ LINE_PARSER
611 STRING_FIELD (addr, isspace, 1);
612
613 /* Parse address. */
614- if (inet_pton (af == AF_UNSPEC ? AF_INET : af, addr, entdata->host_addr)
615+ if (__inet_pton (af == AF_UNSPEC ? AF_INET : af, addr, entdata->host_addr)
616 > 0)
617 af = af == AF_UNSPEC ? AF_INET : af;
618 else
619 {
620- if (af == AF_INET && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
621+ if (af == AF_INET
622+ && __inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
623 {
624 if (IN6_IS_ADDR_V4MAPPED (entdata->host_addr))
625 memcpy (entdata->host_addr, entdata->host_addr + 12, INADDRSZ);
626@@ -76,7 +75,7 @@ LINE_PARSER
627 return 0;
628 }
629 else if (af == AF_UNSPEC
630- && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
631+ && __inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
632 af = AF_INET6;
633 else
634 /* Illegal address: ignore line. */
635@@ -349,7 +348,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
636 status = gethostbyname3_multi
637 (stream, name, af, result, buffer, buflen, errnop, herrnop);
638
639- internal_endent (&stream);
640+ fclose (stream);
641 }
642
643 if (canonp && status == NSS_STATUS_SUCCESS)
644@@ -357,6 +356,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
645
646 return status;
647 }
648+libc_hidden_def (_nss_files_gethostbyname3_r)
649
650 enum nss_status
651 _nss_files_gethostbyname_r (const char *name, struct hostent *result,
652@@ -366,6 +366,7 @@ _nss_files_gethostbyname_r (const char *name, struct hostent *result,
653 return _nss_files_gethostbyname3_r (name, AF_INET, result, buffer, buflen,
654 errnop, herrnop, NULL, NULL);
655 }
656+libc_hidden_def (_nss_files_gethostbyname_r)
657
658 enum nss_status
659 _nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result,
660@@ -375,6 +376,7 @@ _nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result,
661 return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen,
662 errnop, herrnop, NULL, NULL);
663 }
664+libc_hidden_def (_nss_files_gethostbyname2_r)
665
666 enum nss_status
667 _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
668@@ -475,7 +477,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
669 status = NSS_STATUS_SUCCESS;
670 }
671
672- internal_endent (&stream);
673+ fclose (stream);
674 }
675 else if (status == NSS_STATUS_TRYAGAIN)
676 {
677@@ -490,3 +492,4 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
678
679 return status;
680 }
681+libc_hidden_def (_nss_files_gethostbyname4_r)
682diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c
683index 717c9fd334..18ed288d04 100644
684--- a/nss/nss_files/files-init.c
685+++ b/nss/nss_files/files-init.c
686@@ -21,8 +21,7 @@
687 #include <string.h>
688 #include <nscd/nscd.h>
689 #include <nss.h>
690-
691-NSS_DECLARE_MODULE_FUNCTIONS (files)
692+#include <nss_files.h>
693
694 static void
695 register_file (void (*cb) (size_t, struct traced_file *),
696@@ -49,5 +48,6 @@ _nss_files_init (void (*cb) (size_t, struct traced_file *))
697 register_file (cb, servdb, "/etc/services", 0);
698 register_file (cb, netgrdb, "/etc/netgroup", 0);
699 }
700+libc_hidden_def (_nss_files_init)
701
702 #endif
703diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c
704index 6fcea40b55..b44211e50b 100644
705--- a/nss/nss_files/files-initgroups.c
706+++ b/nss/nss_files/files-initgroups.c
707@@ -28,8 +28,6 @@
708 #include <nss.h>
709 #include <nss_files.h>
710
711-NSS_DECLARE_MODULE_FUNCTIONS (files)
712-
713 enum nss_status
714 _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
715 long int *size, gid_t **groupsp, long int limit,
716@@ -129,3 +127,4 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
717
718 return status == NSS_STATUS_SUCCESS && !any ? NSS_STATUS_NOTFOUND : status;
719 }
720+libc_hidden_def (_nss_files_initgroups_dyn)
721diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c
722index f8c821c2f0..75bfbd9e44 100644
723--- a/nss/nss_files/files-netgrp.c
724+++ b/nss/nss_files/files-netgrp.c
725@@ -28,11 +28,9 @@
726 #include "netgroup.h"
727 #include <nss_files.h>
728
729-NSS_DECLARE_MODULE_FUNCTIONS (files)
730-
731 #define DATAFILE "/etc/netgroup"
732
733-libnss_files_hidden_proto (_nss_files_endnetgrent)
734+libc_hidden_proto (_nss_files_endnetgrent)
735
736 #define EXPAND(needed) \
737 do \
738@@ -152,7 +150,7 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result)
739
740 return status;
741 }
742-
743+libc_hidden_def (_nss_files_setnetgrent)
744
745 enum nss_status
746 _nss_files_endnetgrent (struct __netgrent *result)
747@@ -164,7 +162,7 @@ _nss_files_endnetgrent (struct __netgrent *result)
748 result->cursor = NULL;
749 return NSS_STATUS_SUCCESS;
750 }
751-libnss_files_hidden_def (_nss_files_endnetgrent)
752+libc_hidden_def (_nss_files_endnetgrent)
753
754 static char *
755 strip_whitespace (char *str)
756@@ -279,7 +277,7 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *result,
757
758 return status;
759 }
760-libnss_files_hidden_def (_nss_netgroup_parseline)
761+libc_hidden_def (_nss_netgroup_parseline)
762
763
764 enum nss_status
765@@ -293,3 +291,4 @@ _nss_files_getnetgrent_r (struct __netgrent *result, char *buffer,
766
767 return status;
768 }
769+libc_hidden_def (_nss_files_getnetgrent_r)
770diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
771index 9cd7d7dc79..217ed78609 100644
772--- a/nss/nss_files/files-network.c
773+++ b/nss/nss_files/files-network.c
774@@ -22,8 +22,6 @@
775 #include <stdint.h>
776 #include <nss.h>
777
778-NSS_DECLARE_MODULE_FUNCTIONS (files)
779-
780 #define ENTNAME netent
781 #define DATABASE "networks"
782 #define NEED_H_ERRNO
783@@ -71,7 +69,7 @@ LINE_PARSER
784 *cp = '\0';
785 addr = newp;
786 }
787- result->n_net = inet_network (addr);
788+ result->n_net = inet_network (addr);
789 result->n_addrtype = AF_INET;
790
791 })
792diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
793index 68c51c7cbf..997eac573a 100644
794--- a/nss/nss_files/files-parse.c
795+++ b/nss/nss_files/files-parse.c
796@@ -74,13 +74,7 @@ struct parser_data
797 /* Export the line parser function so it can be used in nss_db. */
798 # define parser_stclass /* Global */
799 # define parse_line CONCAT(_nss_files_parse_,ENTNAME)
800-# if IS_IN (libc)
801-/* We are defining one of the functions that actually lives in libc
802- because it is used to implement fget*ent and suchlike. */
803-# define nss_files_parse_hidden_def(name) libc_hidden_def (name)
804-# else
805-# define nss_files_parse_hidden_def(name) libnss_files_hidden_def (name)
806-# endif
807+# define nss_files_parse_hidden_def(name) libc_hidden_def (name)
808 #endif
809
810
811diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c
812index 98d082c642..13072692c1 100644
813--- a/nss/nss_files/files-proto.c
814+++ b/nss/nss_files/files-proto.c
815@@ -19,8 +19,6 @@
816 #include <netdb.h>
817 #include <nss.h>
818
819-NSS_DECLARE_MODULE_FUNCTIONS (files)
820-
821 #define ENTNAME protoent
822 #define DATABASE "protocols"
823
824diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c
825index b04165ddde..5c74c6da9b 100644
826--- a/nss/nss_files/files-pwd.c
827+++ b/nss/nss_files/files-pwd.c
828@@ -19,8 +19,6 @@
829 #include <pwd.h>
830 #include <nss.h>
831
832-NSS_DECLARE_MODULE_FUNCTIONS (files)
833-
834 #define STRUCTURE passwd
835 #define ENTNAME pwent
836 #define DATABASE "passwd"
837diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c
838index eeb2725d2c..3dea8f18f2 100644
839--- a/nss/nss_files/files-rpc.c
840+++ b/nss/nss_files/files-rpc.c
841@@ -19,8 +19,6 @@
842 #include <rpc/netdb.h>
843 #include <nss.h>
844
845-NSS_DECLARE_MODULE_FUNCTIONS (files)
846-
847 #define ENTNAME rpcent
848 #define DATABASE "rpc"
849
850diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c
851index f4f0985377..a8d83e094e 100644
852--- a/nss/nss_files/files-service.c
853+++ b/nss/nss_files/files-service.c
854@@ -20,8 +20,6 @@
855 #include <netdb.h>
856 #include <nss.h>
857
858-NSS_DECLARE_MODULE_FUNCTIONS (files)
859-
860 #define ENTNAME servent
861 #define DATABASE "services"
862
863diff --git a/nss/nss_files/files-sgrp.c b/nss/nss_files/files-sgrp.c
864index 6b1c9eac02..213a408e7b 100644
865--- a/nss/nss_files/files-sgrp.c
866+++ b/nss/nss_files/files-sgrp.c
867@@ -19,8 +19,6 @@
868 #include <gshadow.h>
869 #include <nss.h>
870
871-NSS_DECLARE_MODULE_FUNCTIONS (files)
872-
873 #define STRUCTURE sgrp
874 #define ENTNAME sgent
875 #define DATABASE "gshadow"
876diff --git a/nss/nss_files/files-spwd.c b/nss/nss_files/files-spwd.c
877index 976deaf918..d031257a20 100644
878--- a/nss/nss_files/files-spwd.c
879+++ b/nss/nss_files/files-spwd.c
880@@ -19,8 +19,6 @@
881 #include <shadow.h>
882 #include <nss.h>
883
884-NSS_DECLARE_MODULE_FUNCTIONS (files)
885-
886 #define STRUCTURE spwd
887 #define ENTNAME spent
888 #define DATABASE "shadow"
889diff --git a/nss/nss_files_data.c b/nss/nss_files_data.c
890new file mode 100644
891index 0000000000..80fbfe5fff
892--- /dev/null
893+++ b/nss/nss_files_data.c
894@@ -0,0 +1,161 @@
895+/* Returns a pointer to the global nss_files data structure.
896+ Copyright (C) 2021 Free Software Foundation, Inc.
897+ This file is part of the GNU C Library.
898+
899+ The GNU C Library is free software; you can redistribute it and/or
900+ modify it under the terms of the GNU Lesser General Public
901+ License as published by the Free Software Foundation; either
902+ version 2.1 of the License, or (at your option) any later version.
903+
904+ The GNU C Library is distributed in the hope that it will be useful,
905+ but WITHOUT ANY WARRANTY; without even the implied warranty of
906+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
907+ Lesser General Public License for more details.
908+
909+ You should have received a copy of the GNU Lesser General Public
910+ License along with the GNU C Library; if not, see
911+ <https://www.gnu.org/licenses/>. */
912+
913+#include <nss_files.h>
914+
915+#include <allocate_once.h>
916+#include <errno.h>
917+#include <netdb.h>
918+#include <nss.h>
919+#include <stdlib.h>
920+
921+/* This collects all per file-data. */
922+struct nss_files_data
923+{
924+ struct nss_files_per_file_data files[nss_file_count];
925+};
926+
927+/* For use with allocate_once. */
928+static void *nss_files_global;
929+static void *
930+nss_files_global_allocate (void *closure)
931+{
932+ struct nss_files_data *result = malloc (sizeof (*result));
933+ if (result != NULL)
934+ {
935+ for (int i = 0; i < nss_file_count; ++i)
936+ {
937+ result->files[i].stream = NULL;
938+ __libc_lock_init (result->files[i].lock);
939+ }
940+ }
941+ return result;
942+}
943+/* Like __nss_files_data_open, but does not perform the open call. */
944+static enum nss_status
945+__nss_files_data_get (struct nss_files_per_file_data **pdata,
946+ enum nss_files_file file, int *errnop, int *herrnop)
947+{
948+ struct nss_files_data *data = allocate_once (&nss_files_global,
949+ nss_files_global_allocate,
950+ NULL, NULL);
951+ if (data == NULL)
952+ {
953+ if (errnop != NULL)
954+ *errnop = errno;
955+ if (herrnop != NULL)
956+ {
957+ __set_h_errno (NETDB_INTERNAL);
958+ *herrnop = NETDB_INTERNAL;
959+ }
960+ return NSS_STATUS_TRYAGAIN;
961+ }
962+
963+ *pdata = &data->files[file];
964+ __libc_lock_lock ((*pdata)->lock);
965+ return NSS_STATUS_SUCCESS;
966+}
967+
968+/* Helper function for opening the backing file at PATH. */
969+static enum nss_status
970+__nss_files_data_internal_open (struct nss_files_per_file_data *data,
971+ const char *path)
972+{
973+ enum nss_status status = NSS_STATUS_SUCCESS;
974+
975+ if (data->stream == NULL)
976+ {
977+ data->stream = __nss_files_fopen (path);
978+
979+ if (data->stream == NULL)
980+ status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
981+ }
982+
983+ return status;
984+}
985+
986+
987+enum nss_status
988+__nss_files_data_open (struct nss_files_per_file_data **pdata,
989+ enum nss_files_file file, const char *path,
990+ int *errnop, int *herrnop)
991+{
992+ enum nss_status status = __nss_files_data_get (pdata, file, errnop, herrnop);
993+ if (status != NSS_STATUS_SUCCESS)
994+ return status;
995+
996+ /* Be prepared that the set*ent function was not called before. */
997+ if ((*pdata)->stream == NULL)
998+ {
999+ int saved_errno = errno;
1000+ status = __nss_files_data_internal_open (*pdata, path);
1001+ __set_errno (saved_errno);
1002+ if (status != NSS_STATUS_SUCCESS)
1003+ __nss_files_data_put (*pdata);
1004+ }
1005+
1006+ return status;
1007+}
1008+
1009+libc_hidden_def (__nss_files_data_open)
1010+
1011+void
1012+__nss_files_data_put (struct nss_files_per_file_data *data)
1013+{
1014+ __libc_lock_unlock (data->lock);
1015+}
1016+libc_hidden_def (__nss_files_data_put)
1017+
1018+enum nss_status
1019+__nss_files_data_setent (enum nss_files_file file, const char *path)
1020+{
1021+ struct nss_files_per_file_data *data;
1022+ enum nss_status status = __nss_files_data_get (&data, file, NULL, NULL);
1023+ if (status != NSS_STATUS_SUCCESS)
1024+ return status;
1025+
1026+ if (data->stream == NULL)
1027+ status = __nss_files_data_internal_open (data, path);
1028+ else
1029+ rewind (data->stream);
1030+
1031+ __nss_files_data_put (data);
1032+ return status;
1033+}
1034+libc_hidden_def (__nss_files_data_setent)
1035+
1036+enum nss_status
1037+__nss_files_data_endent (enum nss_files_file file)
1038+{
1039+ /* No cleanup is necessary if not initialized. */
1040+ struct nss_files_data *data = atomic_load_acquire (&nss_files_global);
1041+ if (data == NULL)
1042+ return NSS_STATUS_SUCCESS;
1043+
1044+ struct nss_files_per_file_data *fdata = &data->files[file];
1045+ __libc_lock_lock (fdata->lock);
1046+ if (fdata->stream != NULL)
1047+ {
1048+ fclose (fdata->stream);
1049+ fdata->stream = NULL;
1050+ }
1051+ __libc_lock_unlock (fdata->lock);
1052+
1053+ return NSS_STATUS_SUCCESS;
1054+}
1055+libc_hidden_def (__nss_files_data_endent)
1056diff --git a/nss/nss_files_functions.c b/nss/nss_files_functions.c
1057new file mode 100644
1058index 0000000000..85720b4311
1059--- /dev/null
1060+++ b/nss/nss_files_functions.c
1061@@ -0,0 +1,43 @@
1062+/* Direct access for nss_files functions for NSS module loading.
1063+ Copyright (C) 2021 Free Software Foundation, Inc.
1064+ This file is part of the GNU C Library.
1065+
1066+ The GNU C Library is free software; you can redistribute it and/or
1067+ modify it under the terms of the GNU Lesser General Public
1068+ License as published by the Free Software Foundation; either
1069+ version 2.1 of the License, or (at your option) any later version.
1070+
1071+ The GNU C Library is distributed in the hope that it will be useful,
1072+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1073+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1074+ Lesser General Public License for more details.
1075+
1076+ You should have received a copy of the GNU Lesser General Public
1077+ License along with the GNU C Library; if not, see
1078+ <https://www.gnu.org/licenses/>. */
1079+
1080+#include <nss_module.h>
1081+#include <nss_files.h>
1082+
1083+void
1084+__nss_files_functions (nss_module_functions_untyped pointers)
1085+{
1086+ void **fptr = pointers;
1087+
1088+ /* Functions which are not implemented. */
1089+#define _nss_files_getcanonname_r NULL
1090+#define _nss_files_gethostbyaddr2_r NULL
1091+#define _nss_files_getpublickey NULL
1092+#define _nss_files_getsecretkey NULL
1093+#define _nss_files_netname2user NULL
1094+
1095+#undef DEFINE_NSS_FUNCTION
1096+#define DEFINE_NSS_FUNCTION(x) *fptr++ = _nss_files_##x;
1097+#include "function.def"
1098+
1099+#ifdef PTR_MANGLE
1100+ void **end = fptr;
1101+ for (fptr = pointers; fptr != end; ++fptr)
1102+ PTR_MANGLE (*fptr);
1103+#endif
1104+}
1105diff --git a/nss/nss_module.c b/nss/nss_module.c
1106index 60c070c851..7b42c585a4 100644
1107--- a/nss/nss_module.c
1108+++ b/nss/nss_module.c
1109@@ -30,6 +30,7 @@
1110 #include <stdio.h>
1111 #include <stdlib.h>
1112 #include <string.h>
1113+#include <nss_files.h>
1114
1115 /* Suffix after .so of NSS service modules. This is a bit of magic,
1116 but we assume LIBNSS_FILES_SO looks like "libnss_files.so.2" and we
1117@@ -110,10 +111,45 @@ static const function_name nss_function_name_array[] =
1118 #include "function.def"
1119 };
1120
1121+static bool
1122+module_load_nss_files (struct nss_module *module)
1123+{
1124+ if (is_nscd)
1125+ {
1126+ void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
1127+# ifdef PTR_DEMANGLE
1128+ PTR_DEMANGLE (cb);
1129+# endif
1130+ _nss_files_init (cb);
1131+ }
1132+
1133+ /* Initialize the function pointers, following the double-checked
1134+ locking idiom. */
1135+ __libc_lock_lock (nss_module_list_lock);
1136+ switch ((enum nss_module_state) atomic_load_acquire (&module->state))
1137+ {
1138+ case nss_module_uninitialized:
1139+ case nss_module_failed:
1140+ __nss_files_functions (module->functions.untyped);
1141+ module->handle = NULL;
1142+ /* Synchronizes with unlocked __nss_module_load atomic_load_acquire. */
1143+ atomic_store_release (&module->state, nss_module_loaded);
1144+ break;
1145+ case nss_module_loaded:
1146+ /* Nothing to clean up. */
1147+ break;
1148+ }
1149+ __libc_lock_unlock (nss_module_list_lock);
1150+ return true;
1151+}
1152+
1153 /* Internal implementation of __nss_module_load. */
1154 static bool
1155 module_load (struct nss_module *module)
1156 {
1157+ if (strcmp (module->name, "files") == 0)
1158+ return module_load_nss_files (module);
1159+
1160 void *handle;
1161 {
1162 char *shlib_name;
1163@@ -360,7 +396,7 @@ __nss_module_freeres (void)
1164 struct nss_module *current = nss_module_list;
1165 while (current != NULL)
1166 {
1167- if (current->state == nss_module_loaded)
1168+ if (current->state == nss_module_loaded && current->handle != NULL)
1169 __libc_dlclose (current->handle);
1170
1171 struct nss_module *next = current->next;
1172diff --git a/nss/nss_module.h b/nss/nss_module.h
1173index 05c4791d11..c1a1d90b60 100644
1174--- a/nss/nss_module.h
1175+++ b/nss/nss_module.h
1176@@ -38,6 +38,10 @@ struct nss_module_functions
1177 typedef void *nss_module_functions_untyped[sizeof (struct nss_module_functions)
1178 / sizeof (void *)];
1179
1180+/* Locate the nss_files functions, as if by dlopen/dlsym. */
1181+void __nss_files_functions (nss_module_functions_untyped pointers)
1182+ attribute_hidden;
1183+
1184 /* Initialization state of a NSS module. */
1185 enum nss_module_state
1186 {
1187diff --git a/nss/nss_readline.c b/nss/nss_readline.c
1188index 4b3ecbccc8..a2f397a11f 100644
1189--- a/nss/nss_readline.c
1190+++ b/nss/nss_readline.c
1191@@ -40,7 +40,7 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset)
1192 *poffset = __ftello64 (fp);
1193
1194 buf[len - 1] = '\xff'; /* Marker to recognize truncation. */
1195- if (fgets_unlocked (buf, len, fp) == NULL)
1196+ if (__fgets_unlocked (buf, len, fp) == NULL)
1197 {
1198 if (feof_unlocked (fp))
1199 {
1200@@ -61,7 +61,7 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset)
1201 line on the next call. */
1202 return __nss_readline_seek (fp, *poffset);
1203
1204- /* fgets_unlocked succeeded. */
1205+ /* __fgets_unlocked succeeded. */
1206
1207 /* Remove leading whitespace. */
1208 char *p = buf;
1209diff --git a/nss/nss.h b/nss/nss.h
1210index ae213f9a6c..c6d62adc0f 100644
1211--- a/nss/nss.h
1212+++ b/nss/nss.h
1213@@ -196,7 +196,7 @@ typedef enum nss_status nss_setspent (int);
1214 extern nss_endgrent _nss_##module##_endgrent; \
1215 extern nss_endhostent _nss_##module##_endhostent; \
1216 extern nss_endnetent _nss_##module##_endnetent; \
1217- extern nss_endnetgrent _nss_##module##__endnetgrent; \
1218+ extern nss_endnetgrent _nss_##module##_endnetgrent; \
1219 extern nss_endprotoent _nss_##module##_endprotoent; \
1220 extern nss_endpwent _nss_##module##_endpwent; \
1221 extern nss_endrpcent _nss_##module##_endrpcent; \
1222diff --git a/nss/nss_module.c b/nss/nss_module.c
1223index 7b42c585a4..7ea5ad9887 100644
1224--- a/nss/nss_module.c
1225+++ b/nss/nss_module.c
1226@@ -114,14 +114,16 @@ static const function_name nss_function_name_array[] =
1227 static bool
1228 module_load_nss_files (struct nss_module *module)
1229 {
1230+#ifdef USE_NSCD
1231 if (is_nscd)
1232 {
1233 void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
1234-# ifdef PTR_DEMANGLE
1235+# ifdef PTR_DEMANGLE
1236 PTR_DEMANGLE (cb);
1237-# endif
1238+# endif
1239 _nss_files_init (cb);
1240 }
1241+#endif
1242
1243 /* Initialize the function pointers, following the double-checked
1244 locking idiom. */