summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/grent.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp/grent.c')
-rw-r--r--libc/pwd_grp/grent.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c
index 587fe0d93..9418ea937 100644
--- a/libc/pwd_grp/grent.c
+++ b/libc/pwd_grp/grent.c
@@ -40,6 +40,16 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
# define UNLOCK
#endif
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+extern pthread_mutex_t __getgrent_lock;
+# define GRENT_LOCK pthread_mutex_lock(&__getgrent_lock)
+# define GRENT_UNLOCK pthread_mutex_unlock(&__getgrent_lock);
+#else
+# define GRENT_LOCK
+# define GRENT_UNLOCK
+#endif
+
static int grp_fd = -1;
static char *line_buff = NULL;
static char **members = NULL;
@@ -71,7 +81,9 @@ struct group *getgrent(void)
UNLOCK;
return NULL;
}
- r = __getgrent(grp_fd, line_buff, members);
UNLOCK;
+ GRENT_LOCK;
+ r = __getgrent(grp_fd, line_buff, members);
+ GRENT_UNLOCK;
return r;
}