Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net Throw in mutex stubs to serialize access to the...



details:   https://anonhg.NetBSD.org/src/rev/d2a8a3d02742
branches:  trunk
changeset: 572544:d2a8a3d02742
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Fri Jan 07 22:22:49 2005 +0000

description:
Throw in mutex stubs to serialize access to the legacy global structures.

diffstat:

 lib/libc/net/getprotobyname.c   |  18 +++++++++++++-----
 lib/libc/net/getprotobynumber.c |  17 +++++++++++++----
 lib/libc/net/getprotoent.c      |  20 +++++++++++++++++---
 lib/libc/net/getservbyname.c    |  19 +++++++++++++------
 lib/libc/net/getservbyport.c    |  17 +++++++++++++----
 lib/libc/net/getservent.c       |  20 +++++++++++++++++---
 6 files changed, 86 insertions(+), 25 deletions(-)

diffs (293 lines):

diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getprotobyname.c
--- a/lib/libc/net/getprotobyname.c     Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getprotobyname.c     Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getprotobyname.c,v 1.1 2004/02/19 19:27:26 christos Exp $      */
+/*     $NetBSD: getprotobyname.c,v 1.2 2005/01/07 22:22:49 mycroft Exp $       */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -37,22 +37,30 @@
  */
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getprotobyname.c,v 1.1 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getprotobyname.c,v 1.2 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
-#include <assert.h>
+#include "reentrant.h"
+
 #include <netdb.h>
-#include <string.h>
 
 #ifdef __weak_alias
 __weak_alias(getprotobyname,_getprotobyname)
 #endif
 
+#ifdef _REENTRANT
+extern mutex_t _protoent_mutex;
+#endif
 extern struct protoent_data _protoent_data;
 
 struct protoent *
 getprotobyname(const char *name)
 {
-       return getprotobyname_r(name, &_protoent_data.proto, &_protoent_data);
+       struct protoent *p;
+
+       mutex_lock(&_protoent_mutex);
+       p = getprotobyname_r(name, &_protoent_data.proto, &_protoent_data);
+       mutex_unlock(&_protoent_mutex);
+       return (p);
 }
diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getprotobynumber.c
--- a/lib/libc/net/getprotobynumber.c   Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getprotobynumber.c   Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getprotobynumber.c,v 1.1 2004/02/19 19:27:26 christos Exp $    */
+/*     $NetBSD: getprotobynumber.c,v 1.2 2005/01/07 22:22:49 mycroft Exp $     */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -38,21 +38,30 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getprotobynumber.c,v 1.1 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getprotobynumber.c,v 1.2 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+#include "reentrant.h"
+
 #include <netdb.h>
 
 #ifdef __weak_alias
 __weak_alias(getprotobynumber,_getprotobynumber)
 #endif
 
+#ifdef _REENTRANT
+extern mutex_t _protoent_mutex;
+#endif
 extern struct protoent_data _protoent_data;
 
 struct protoent *
 getprotobynumber(int proto)
 {
-       return getprotobynumber_r(proto, &_protoent_data.proto,
-           &_protoent_data);
+       struct protoent *p;
+
+       mutex_lock(&_protoent_mutex);
+       p = getprotobynumber_r(proto, &_protoent_data.proto, &_protoent_data);
+       mutex_unlock(&_protoent_mutex);
+       return (p);
 }
diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getprotoent.c
--- a/lib/libc/net/getprotoent.c        Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getprotoent.c        Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getprotoent.c,v 1.9 2004/02/19 19:27:26 christos Exp $ */
+/*     $NetBSD: getprotoent.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -38,10 +38,12 @@
 #include <sys/cdefs.h>
 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getprotoent.c,v 1.9 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getprotoent.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+#include "reentrant.h"
+
 #include <netdb.h>
 
 #ifdef __weak_alias
@@ -50,22 +52,34 @@
 __weak_alias(setprotoent,_setprotoent)
 #endif
 
+#ifdef _REENTRANT
+mutex_t _protoent_mutex = MUTEX_INITIALIZER;
+#endif
 struct protoent_data _protoent_data;
 
 void
 setprotoent(int f)
 {
+       mutex_lock(&_protoent_mutex);
        setprotoent_r(f, &_protoent_data);
+       mutex_unlock(&_protoent_mutex);
 }
 
 void
 endprotoent(void)
 {
+       mutex_lock(&_protoent_mutex);
        endprotoent_r(&_protoent_data);
+       mutex_unlock(&_protoent_mutex);
 }
 
 struct protoent *
 getprotoent(void)
 {
-       return getprotoent_r(&_protoent_data.proto, &_protoent_data);
+       struct protoent *p;
+
+       mutex_lock(&_protoent_mutex);
+       p = getprotoent_r(&_protoent_data.proto, &_protoent_data);
+       mutex_unlock(&_protoent_mutex);
+       return (p);
 }
diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getservbyname.c
--- a/lib/libc/net/getservbyname.c      Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getservbyname.c      Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getservbyname.c,v 1.11 2004/02/19 19:27:26 christos Exp $      */
+/*     $NetBSD: getservbyname.c,v 1.12 2005/01/07 22:22:49 mycroft Exp $       */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -37,23 +37,30 @@
  */
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getservbyname.c,v 1.11 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getservbyname.c,v 1.12 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
-#include <assert.h>
+#include "reentrant.h"
+
 #include <netdb.h>
-#include <string.h>
 
 #ifdef __weak_alias
 __weak_alias(getservbyname,_getservbyname)
 #endif
 
+#ifdef _REENTRANT
+extern mutex_t _servent_mutex;
+#endif
 extern struct servent_data _servent_data;
 
 struct servent *
 getservbyname(const char *name, const char *proto)
 {
-       return getservbyname_r(name, proto,
-           &_servent_data.serv, &_servent_data);
+       struct servent *s;
+
+       mutex_lock(&_servent_mutex);
+       s = getservbyname_r(name, proto, &_servent_data.serv, &_servent_data);
+       mutex_unlock(&_servent_mutex);
+       return (s);
 }
diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getservbyport.c
--- a/lib/libc/net/getservbyport.c      Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getservbyport.c      Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getservbyport.c,v 1.9 2004/02/19 19:27:26 christos Exp $       */
+/*     $NetBSD: getservbyport.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $       */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -38,21 +38,30 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getservbyport.c,v 1.9 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getservbyport.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+#include "reentrant.h"
+
 #include <netdb.h>
 
 #ifdef __weak_alias
 __weak_alias(getservbyport,_getservbyport)
 #endif
 
+#ifdef _REENTRANT
+extern mutex_t _servent_mutex;
+#endif
 extern struct servent_data _servent_data;
 
 struct servent *
 getservbyport(int port, const char *proto)
 {
-       return getservbyport_r(port, proto, &_servent_data.serv,
-           &_servent_data);
+       struct servent *s;
+
+       mutex_lock(&_servent_mutex);
+       s = getservbyport_r(port, proto, &_servent_data.serv, &_servent_data);
+       mutex_unlock(&_servent_mutex);
+       return (s);
 }
diff -r 0e26a3248665 -r d2a8a3d02742 lib/libc/net/getservent.c
--- a/lib/libc/net/getservent.c Fri Jan 07 21:31:04 2005 +0000
+++ b/lib/libc/net/getservent.c Fri Jan 07 22:22:49 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getservent.c,v 1.9 2004/02/19 19:27:26 christos Exp $  */
+/*     $NetBSD: getservent.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $  */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -38,10 +38,12 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getservent.c,v 1.9 2004/02/19 19:27:26 christos Exp $");
+__RCSID("$NetBSD: getservent.c,v 1.10 2005/01/07 22:22:49 mycroft Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
+#include "reentrant.h"
+
 #include <netdb.h>
 
 #ifdef __weak_alias
@@ -50,22 +52,34 @@
 __weak_alias(setservent,_setservent)
 #endif
 
+#ifdef _REENTRANT
+mutex_t _servent_mutex = MUTEX_INITIALIZER;
+#endif
 struct servent_data _servent_data;
 
 void
 setservent(int f)
 {
+       mutex_lock(&_servent_mutex);
        setservent_r(f, &_servent_data);
+       mutex_unlock(&_servent_mutex);
 }
 
 void
 endservent(void)
 {
+       mutex_lock(&_servent_mutex);
        endservent_r(&_servent_data);
+       mutex_unlock(&_servent_mutex);
 }
 
 struct servent *
 getservent(void)
 {
-       return getservent_r(&_servent_data.serv, &_servent_data);
+       struct servent *s;
+
+       mutex_lock(&_servent_mutex);
+       s = getservent_r(&_servent_data.serv, &_servent_data);
+       mutex_unlock(&_servent_mutex);
+       return (s);
 }



Home | Main Index | Thread Index | Old Index