diff options
author | ume <ume@FreeBSD.org> | 2005-04-05 18:07:59 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2005-04-05 18:07:59 +0000 |
commit | ac4b9096b3b49b73828190512f14be0d7ca1a714 (patch) | |
tree | b38b77569af837f8384bd8973c3dacba0a9395b8 /lib/libc/yp | |
parent | d64c6a588b1a748d63f3a403d1165720570355c8 (diff) | |
download | FreeBSD-src-ac4b9096b3b49b73828190512f14be0d7ca1a714.zip FreeBSD-src-ac4b9096b3b49b73828190512f14be0d7ca1a714.tar.gz |
protect _yp_domain with mutex lock.
Inspired by: NetBSD
Diffstat (limited to 'lib/libc/yp')
-rw-r--r-- | lib/libc/yp/yplib.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index 6d220ed..3ba6b3f 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" +#include "reentrant.h" #include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> @@ -104,6 +105,10 @@ struct dom_binding *_ypbindlist; static char _yp_domain[MAXHOSTNAMELEN]; int _yplib_timeout = 10; +static mutex_t _ypmutex = PTHREAD_MUTEX_INITIALIZER; +#define YPLOCK() mutex_lock(&_ypmutex); +#define YPUNLOCK() mutex_unlock(&_ypmutex); + #ifdef YPMATCHCACHE static void ypmatch_cache_delete(struct dom_binding *ypdb, struct ypmatch_ent *prev, @@ -686,8 +691,8 @@ again: return (r); } -int -yp_get_default_domain(char **domp) +static int +yp_get_default_domain_locked(char **domp) { *domp = NULL; if (_yp_domain[0] == '\0') @@ -698,6 +703,17 @@ yp_get_default_domain(char **domp) } int +yp_get_default_domain(char **domp) +{ + int r; + + YPLOCK(); + r = yp_get_default_domain_locked(domp); + YPUNLOCK(); + return (r); +} + +int yp_first(char *indomain, char *inmap, char **outkey, int *outkeylen, char **outval, int *outvallen) { @@ -1078,16 +1094,21 @@ _yp_check(char **dom) { char *unused; + YPLOCK(); if (_yp_domain[0]=='\0') - if (yp_get_default_domain(&unused)) + if (yp_get_default_domain_locked(&unused)) { + YPUNLOCK(); return (0); + } if (dom) *dom = _yp_domain; if (yp_bind(_yp_domain) == 0) { yp_unbind(_yp_domain); + YPUNLOCK(); return (1); } + YPUNLOCK(); return (0); } |