diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-07-16 16:12:46 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-07-21 07:32:46 +0200 |
commit | 299210c1fa67e2dfb564475986fce11cd33db9ad (patch) | |
tree | 7230de5a2b2d0556428f53f28d2d5f2ccfad12d8 /nss/nss_files | |
parent | 469c03907b116c37c98d8ad7a9edac2bdbf3e934 (diff) | |
download | glibc-299210c1fa67e2dfb564475986fce11cd33db9ad.tar glibc-299210c1fa67e2dfb564475986fce11cd33db9ad.tar.gz glibc-299210c1fa67e2dfb564475986fce11cd33db9ad.tar.bz2 glibc-299210c1fa67e2dfb564475986fce11cd33db9ad.zip |
nss_files: Consolidate file opening in __nss_files_fopen
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'nss/nss_files')
-rw-r--r-- | nss/nss_files/files-XXX.c | 3 | ||||
-rw-r--r-- | nss/nss_files/files-alias.c | 5 | ||||
-rw-r--r-- | nss/nss_files/files-initgroups.c | 6 | ||||
-rw-r--r-- | nss/nss_files/files-netgrp.c | 5 |
4 files changed, 9 insertions, 10 deletions
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index 73d2d5cb31..9cc5137953 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -22,6 +22,7 @@ #include <fcntl.h> #include <libc-lock.h> #include "nsswitch.h" +#include <nss_files.h> #include <kernel-features.h> @@ -74,7 +75,7 @@ internal_setent (FILE **stream) if (*stream == NULL) { - *stream = fopen (DATAFILE, "rce"); + *stream = __nss_files_fopen (DATAFILE); if (*stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 6aff7b4c10..43fb2c49a5 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -29,6 +29,7 @@ #include <kernel-features.h> #include "nsswitch.h" +#include <nss_files.h> NSS_DECLARE_MODULE_FUNCTIONS (files) @@ -49,7 +50,7 @@ internal_setent (FILE **stream) if (*stream == NULL) { - *stream = fopen ("/etc/aliases", "rce"); + *stream = __nss_files_fopen ("/etc/aliases"); if (*stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; @@ -215,7 +216,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, first_unused = cp; - listfile = fopen (&cp[9], "rce"); + listfile = __nss_files_fopen (&cp[9]); /* If the file does not exist we simply ignore the statement. */ if (listfile != NULL diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c index 577d6ddf1e..b6f505984a 100644 --- a/nss/nss_files/files-initgroups.c +++ b/nss/nss_files/files-initgroups.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <scratch_buffer.h> #include <nss.h> +#include <nss_files.h> NSS_DECLARE_MODULE_FUNCTIONS (files) @@ -34,16 +35,13 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { - FILE *stream = fopen ("/etc/group", "rce"); + FILE *stream = __nss_files_fopen ("/etc/group"); if (stream == NULL) { *errnop = errno; return *errnop == ENOMEM ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; } - /* No other thread using this stream. */ - __fsetlocking (stream, FSETLOCKING_BYCALLER); - char *line = NULL; size_t linelen = 0; enum nss_status status = NSS_STATUS_SUCCESS; diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c index 2c580af01d..66e16b7c77 100644 --- a/nss/nss_files/files-netgrp.c +++ b/nss/nss_files/files-netgrp.c @@ -26,6 +26,7 @@ #include <string.h> #include "nsswitch.h" #include "netgroup.h" +#include <nss_files.h> NSS_DECLARE_MODULE_FUNCTIONS (files) @@ -64,7 +65,7 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result) return NSS_STATUS_UNAVAIL; /* Find the netgroups file and open it. */ - fp = fopen (DATAFILE, "rce"); + fp = __nss_files_fopen (DATAFILE); if (fp == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; else @@ -78,8 +79,6 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result) status = NSS_STATUS_NOTFOUND; result->cursor = result->data; - __fsetlocking (fp, FSETLOCKING_BYCALLER); - while (!feof_unlocked (fp)) { ssize_t curlen = getline (&line, &line_len, fp); |