From f6cfb61578920a2aba19afbf320e007efd863730 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 8 Aug 2002 07:28:33 +0000 Subject: Fix locking -Erik --- libc/pwd_grp/sgetspent.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libc/pwd_grp/sgetspent.c') diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c index 83b1144ee..1925a78ec 100644 --- a/libc/pwd_grp/sgetspent.c +++ b/libc/pwd_grp/sgetspent.c @@ -17,10 +17,21 @@ * */ +#include #include #include #include "config.h" +#ifdef __UCLIBC_HAS_THREADS__ +#include +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 + int sgetspent_r (const char *string, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { @@ -32,8 +43,11 @@ struct spwd *sgetspent(const char *string) static char line_buff[PWD_BUFFER_SIZE]; static struct spwd spwd; + LOCK; if (sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { + UNLOCK; return &spwd; } + UNLOCK; return NULL; } -- cgit v1.2.3