add a simple lock in _yp_check(), to make it re-entrant.

This commit is contained in:
christos 2004-05-27 18:41:11 +00:00
parent 71fe243008
commit 04562cac02

View File

@ -1,4 +1,4 @@
/* $NetBSD: yplib.c,v 1.40 2003/12/10 12:06:25 agc Exp $ */
/* $NetBSD: yplib.c,v 1.41 2004/05/27 18:41:11 christos Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: yplib.c,v 1.40 2003/12/10 12:06:25 agc Exp $");
__RCSID("$NetBSD: yplib.c,v 1.41 2004/05/27 18:41:11 christos Exp $");
#endif
#include "namespace.h"
@ -50,6 +50,7 @@ __RCSID("$NetBSD: yplib.c,v 1.40 2003/12/10 12:06:25 agc Exp $");
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <threadlib.h>
#include "local.h"
#define BINDINGDIR "/var/yp/binding"
@ -72,6 +73,15 @@ __weak_alias(yp_unbind, _yp_unbind)
__weak_alias(yp_get_default_domain, _yp_get_default_domain)
#endif
#ifdef _REENTRANT
static mutex_t _ypmutex = MUTEX_INITIALIZER;
#define YPLOCK() mutex_lock(&_ypmutex)
#define YPUNLOCK() mutex_unlock(&_ypmutex)
#else
#define YPLOCK()
#define YPUNLOCK()
#endif
int
_yp_dobind(dom, ypdb)
const char *dom;
@ -318,17 +328,22 @@ _yp_check(dom)
char **dom;
{
char *unused;
int good;
YPLOCK();
if (_yp_domain[0] == '\0')
if (yp_get_default_domain(&unused))
return 0;
if (yp_get_default_domain(&unused)) {
good = 0;
goto done;
}
if (dom)
*dom = _yp_domain;
if (yp_bind(_yp_domain) == 0)
return 1;
return 0;
good = yp_bind(_yp_domain) == 0;
done:
YPUNLOCK();
return good;
}
/*