Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/yp add a simple lock in _yp_check(), to make it re-...



details:   https://anonhg.NetBSD.org/src/rev/79a13fa2989b
branches:  trunk
changeset: 567009:79a13fa2989b
user:      christos <christos%NetBSD.org@localhost>
date:      Thu May 27 18:41:11 2004 +0000

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

diffstat:

 lib/libc/yp/yplib.c |  31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diffs (71 lines):

diff -r fed46dec298c -r 79a13fa2989b lib/libc/yp/yplib.c
--- a/lib/libc/yp/yplib.c       Thu May 27 18:40:07 2004 +0000
+++ b/lib/libc/yp/yplib.c       Thu May 27 18:41:11 2004 +0000
@@ -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@localhost>
@@ -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 @@
 #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_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 @@
        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;
 }
 
 /*



Home | Main Index | Thread Index | Old Index