aboutsummaryrefslogtreecommitdiff
path: root/nss/nss_files/files-alias.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-07-07 18:33:52 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-07-07 18:33:52 +0200
commit36861a968ad143f662db489cd8f859186ee375c2 (patch)
treea12995bb4eda7c1e6822b13a3e38efcb27dd1678 /nss/nss_files/files-alias.c
parentf0c28504a9877be5da3ed1215f2da2d5914bbb0b (diff)
downloadglibc-36861a968ad143f662db489cd8f859186ee375c2.tar
glibc-36861a968ad143f662db489cd8f859186ee375c2.tar.gz
glibc-36861a968ad143f662db489cd8f859186ee375c2.tar.bz2
glibc-36861a968ad143f662db489cd8f859186ee375c2.zip
nss_files: Add generic code for set*ent, end*ent and file open
This reduces RSS usage if nss_files is not actually used, and can be used later to make NSS data thread-specific. It also results in a small code size reduction. Before: text data bss dec hex filename 2288 0 72 2360 938 nss/files-alias.os 1807 0 72 1879 757 nss/files-ethers.os 1371 0 72 1443 5a3 nss/files-grp.os 6246 0 72 6318 18ae nss/files-hosts.os 869 0 0 869 365 nss/files-initgroups.os 666 0 0 666 29a nss/files-init.os 1934 0 0 1934 78e nss/files-netgrp.os 2353 0 72 2425 979 nss/files-network.os 2130 0 72 2202 89a nss/files-proto.os 1372 0 72 1444 5a4 nss/files-pwd.os 2124 0 72 2196 894 nss/files-rpc.os 2265 0 72 2337 921 nss/files-service.os 1125 0 72 1197 4ad nss/files-sgrp.os 1124 0 72 1196 4ac nss/files-spwd.os After: text data bss dec hex filename 2040 0 0 2040 7f8 nss/files-alias.os 1599 0 0 1599 63f nss/files-ethers.os 1155 0 0 1155 483 nss/files-grp.os 6010 0 0 6010 177a nss/files-hosts.os 869 0 0 869 365 nss/files-initgroups.os 666 0 0 666 29a nss/files-init.os 1934 0 0 1934 78e nss/files-netgrp.os 2129 0 0 2129 851 nss/files-network.os 1914 0 0 1914 77a nss/files-proto.os 1156 0 0 1156 484 nss/files-pwd.os 1908 0 0 1908 774 nss/files-rpc.os 2057 0 0 2057 809 nss/files-service.os 909 0 0 909 38d nss/files-sgrp.os 908 0 0 908 38c nss/files-spwd.os 1090 0 8 1098 44a nss/nss_files_data.os 27674 code bytes before, 26344 code bytes after, so it is an overall win despite the extra initialization code. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nss/nss_files/files-alias.c')
-rw-r--r--nss/nss_files/files-alias.c69
1 files changed, 16 insertions, 53 deletions
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 30971bfe56..9624b6224c 100644
--- a/nss/nss_files/files-alias.c
+++ b/nss/nss_files/files-alias.c
@@ -33,16 +33,11 @@
NSS_DECLARE_MODULE_FUNCTIONS (files)
-/* Locks the static variables in this file. */
-__libc_lock_define_initialized (static, lock)
/* Maintenance of the stream open on the database file. For getXXent
operations the stream needs to be held open across calls, the other
getXXbyYY operations all use their own stream. */
-static FILE *stream;
-
-
static enum nss_status
internal_setent (FILE **stream)
{
@@ -66,41 +61,13 @@ internal_setent (FILE **stream)
enum nss_status
_nss_files_setaliasent (void)
{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_setent (&stream);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-/* Close the database file. */
-static void
-internal_endent (FILE **stream)
-{
- if (*stream != NULL)
- {
- fclose (*stream);
- *stream = NULL;
- }
+ return __nss_files_data_setent (nss_file_aliasent, "/etc/aliases");
}
-
-/* Thread-safe, exported version of that. */
enum nss_status
_nss_files_endaliasent (void)
{
- __libc_lock_lock (lock);
-
- internal_endent (&stream);
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
+ return __nss_files_data_endent (nss_file_aliasent);
}
/* Parsing the database file into `struct aliasent' data structures. */
@@ -369,26 +336,22 @@ _nss_files_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen,
int *errnop)
{
/* Return next entry in host file. */
- enum nss_status status = NSS_STATUS_SUCCESS;
- __libc_lock_lock (lock);
+ struct nss_files_per_file_data *data;
+ enum nss_status status = __nss_files_data_open (&data, nss_file_aliasent,
+ "/etc/aliases", errnop, NULL);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
- /* Be prepared that the set*ent function was not called before. */
- if (stream == NULL)
- status = internal_setent (&stream);
+ result->alias_local = 1;
- if (status == NSS_STATUS_SUCCESS)
- {
- result->alias_local = 1;
-
- /* Read lines until we get a definite result. */
- do
- status = get_next_alias (stream, NULL, result, buffer, buflen, errnop);
- while (status == NSS_STATUS_RETURN);
- }
-
- __libc_lock_unlock (lock);
+ /* Read lines until we get a definite result. */
+ do
+ status = get_next_alias (data->stream, NULL, result, buffer, buflen,
+ errnop);
+ while (status == NSS_STATUS_RETURN);
+ __nss_files_data_put (data);
return status;
}
@@ -418,9 +381,9 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result,
do
status = get_next_alias (stream, name, result, buffer, buflen, errnop);
while (status == NSS_STATUS_RETURN);
- }
- internal_endent (&stream);
+ fclose (stream);
+ }
return status;
}