summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-09-10 05:53:30 +0000
committerEric Andersen <andersen@codepoet.org>2002-09-10 05:53:30 +0000
commit431fc6465d32db324360e947bb55cf972e85cf84 (patch)
tree48f6b77281a4d10e929ad35c075e54464ebe7785 /libc
parentbee4f83a21cf7ca9937f7c69020cd44e076c9591 (diff)
Fix some locking problems noted by Manuel. __getgrent() was always
called under lock, but the callers did not share the same locks... -Erik
Diffstat (limited to 'libc')
-rw-r--r--libc/pwd_grp/__getgrent.c10
-rw-r--r--libc/pwd_grp/fgetgrent.c7
-rw-r--r--libc/pwd_grp/getgrgid.c6
-rw-r--r--libc/pwd_grp/getgrnam.c6
-rw-r--r--libc/pwd_grp/grent.c14
-rw-r--r--libc/pwd_grp/initgroups.c10
6 files changed, 32 insertions, 21 deletions
diff --git a/libc/pwd_grp/__getgrent.c b/libc/pwd_grp/__getgrent.c
index 393c42de1..b896a976a 100644
--- a/libc/pwd_grp/__getgrent.c
+++ b/libc/pwd_grp/__getgrent.c
@@ -24,14 +24,12 @@
#include <string.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
+/* This function should always be called under lock, so we
+ * do not lock things in here... */
+pthread_mutex_t __getgrent_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
/*
diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c
index b99df1c77..2c7917601 100644
--- a/libc/pwd_grp/fgetgrent.c
+++ b/libc/pwd_grp/fgetgrent.c
@@ -24,13 +24,14 @@
#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);
+extern pthread_mutex_t __getgrent_lock;
+# define LOCK pthread_mutex_lock(&__getgrent_lock)
+# define UNLOCK pthread_mutex_unlock(&__getgrent_lock);
#else
# define LOCK
# define UNLOCK
#endif
+
static char *line_buff = NULL;
static char **members = NULL;
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
index 5efca964a..3575a749b 100644
--- a/libc/pwd_grp/getgrgid.c
+++ b/libc/pwd_grp/getgrgid.c
@@ -27,9 +27,9 @@
#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);
+extern pthread_mutex_t __getgrent_lock;
+# define LOCK pthread_mutex_lock(&__getgrent_lock)
+# define UNLOCK pthread_mutex_unlock(&__getgrent_lock);
#else
# define LOCK
# define UNLOCK
diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c
index 10302aab2..2c8d030e0 100644
--- a/libc/pwd_grp/getgrnam.c
+++ b/libc/pwd_grp/getgrnam.c
@@ -27,9 +27,9 @@
#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);
+extern pthread_mutex_t __getgrent_lock;
+# define LOCK pthread_mutex_lock(&__getgrent_lock)
+# define UNLOCK pthread_mutex_unlock(&__getgrent_lock);
#else
# define LOCK
# define UNLOCK
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;
}
diff --git a/libc/pwd_grp/initgroups.c b/libc/pwd_grp/initgroups.c
index 1596298e8..84ead9c55 100644
--- a/libc/pwd_grp/initgroups.c
+++ b/libc/pwd_grp/initgroups.c
@@ -27,13 +27,13 @@
#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
+extern pthread_mutex_t __getgrent_lock;
+# define LOCK pthread_mutex_lock(&__getgrent_lock)
+# define UNLOCK pthread_mutex_unlock(&__getgrent_lock);
+#else
# define LOCK
# define UNLOCK
-#endif
+#endif
static char *line_buff = NULL;
static char **members = NULL;