summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/grent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-08-08 07:28:33 +0000
committerEric Andersen <andersen@codepoet.org>2002-08-08 07:28:33 +0000
commitf6cfb61578920a2aba19afbf320e007efd863730 (patch)
treeccb2c728bbc974843bcdcad15be710ca0fdc432c /libc/pwd_grp/grent.c
parent82dc33223c219e05fe2637f675e11cd85438f7be (diff)
Fix locking
-Erik
Diffstat (limited to 'libc/pwd_grp/grent.c')
-rw-r--r--libc/pwd_grp/grent.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c
index 42db9f9b6..f867a1aaf 100644
--- a/libc/pwd_grp/grent.c
+++ b/libc/pwd_grp/grent.c
@@ -24,30 +24,47 @@
* in together.
*/
+#include <features.h>
#include <unistd.h>
#include <fcntl.h>
#include <paths.h>
#include "config.h"
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
+# define LOCK pthread_mutex_lock(&mylock)
+# define UNLOCK pthread_mutex_unlock(&mylock);
+#else
+# define LOCK
+# define UNLOCK
+#endif
+
static int grp_fd = -1;
void setgrent(void)
{
- if (grp_fd != -1)
- close(grp_fd);
- grp_fd = open(_PATH_GROUP, O_RDONLY);
+ LOCK;
+ if (grp_fd != -1)
+ close(grp_fd);
+ grp_fd = open(_PATH_GROUP, O_RDONLY);
+ UNLOCK;
}
void endgrent(void)
{
- if (grp_fd != -1)
- close(grp_fd);
- grp_fd = -1;
+ LOCK;
+ if (grp_fd != -1)
+ close(grp_fd);
+ grp_fd = -1;
+ UNLOCK;
}
struct group *getgrent(void)
{
- if (grp_fd == -1)
- return NULL;
- return __getgrent(grp_fd);
+ LOCK;
+ if (grp_fd == -1)
+ return NULL;
+ return __getgrent(grp_fd);
+ UNLOCK;
}