diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-11-01 04:40:10 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-11-01 04:40:10 +0000 |
commit | fabd08e8543c01b41f277eb2eb9f731c7b424c36 (patch) | |
tree | e6f38c07b1fa9a3d37f73201e360a039606f6fd9 /libc/pwd_grp/grent.c | |
parent | 9eae73f74c4eee0c661778acc09c5bbf2e42709b (diff) |
Fix things (properly) to open /etc/passd and /etc/group if
they have not yet been opened.
My last try was completely and embarrasingly broken.
-Erik
Diffstat (limited to 'libc/pwd_grp/grent.c')
-rw-r--r-- | libc/pwd_grp/grent.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c index 128520e8c..e05459c2d 100644 --- a/libc/pwd_grp/grent.c +++ b/libc/pwd_grp/grent.c @@ -26,6 +26,7 @@ * in together. */ +#define _GNU_SOURCE #include <features.h> #include <unistd.h> #include <fcntl.h> @@ -35,7 +36,7 @@ #ifdef __UCLIBC_HAS_THREADS__ #include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; # define LOCK pthread_mutex_lock(&mylock) # define UNLOCK pthread_mutex_unlock(&mylock); #else @@ -43,12 +44,13 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; # define UNLOCK #endif -static int grp_fd = -1; +/* file descriptor for the group file currently open */ +static int grp_fd = -9; void setgrent(void) { LOCK; - if (grp_fd != -1) + if (grp_fd > -1) close(grp_fd); grp_fd = open(_PATH_GROUP, O_RDONLY); UNLOCK; @@ -57,7 +59,7 @@ void setgrent(void) void endgrent(void) { LOCK; - if (grp_fd != -1) + if (grp_fd > -1) close(grp_fd); grp_fd = -1; UNLOCK; @@ -70,6 +72,10 @@ struct group *getgrent(void) static char line_buff[PWD_BUFFER_SIZE]; LOCK; + /* Open /etc/group if it has never been opened */ + if (grp_fd == -9) { + setgrent(); + } if (grp_fd == -1) { UNLOCK; return NULL; |