protect _yp_domain with mutex lock.
Inspired by: NetBSD
This commit is contained in:
parent
b9d9b6ef3d
commit
069eb2cafb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=144678
@ -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 @@ yp_match(char *indomain, char *inmap, const char *inkey, int inkeylen,
|
||||
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')
|
||||
@ -697,6 +702,17 @@ yp_get_default_domain(char **domp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user