Browse Source

Fix some locking problems noted by Manuel. __getgrent() was always
called under lock, but the callers did not share the same locks...
-Erik

Eric Andersen 23 years ago
parent
commit
431fc6465d

+ 4 - 6
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
 
 /*

+ 4 - 3
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;
 

+ 3 - 3
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

+ 3 - 3
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

+ 13 - 1
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;
 }

+ 5 - 5
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;