mt_misc.c revision 1.6 1 /* $NetBSD: mt_misc.c,v 1.6 2008/04/25 17:44:44 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Define and initialize MT data for libnsl.
41 * The _libnsl_lock_init() function below is the library's .init handler.
42 */
43
44 /* #pragma ident "@(#)mt_misc.c 1.24 93/04/29 SMI" */
45
46 #include <sys/cdefs.h>
47 #if defined(LIBC_SCCS) && !defined(lint)
48 __RCSID("$NetBSD: mt_misc.c,v 1.6 2008/04/25 17:44:44 christos Exp $");
49 #endif
50
51 #include "namespace.h"
52 #include "reentrant.h"
53 #include <rpc/rpc.h>
54 #include <sys/time.h>
55 #include <stdlib.h>
56 #include <string.h>
57
58 #ifdef _REENTRANT
59
60 /* protects the services list (svc.c) */
61 rwlock_t svc_lock = RWLOCK_INITIALIZER;
62 /* protects svc_fdset and the xports[] array */
63 rwlock_t svc_fd_lock = RWLOCK_INITIALIZER;
64 /* protects the RPCBIND address cache */
65 rwlock_t rpcbaddr_cache_lock = RWLOCK_INITIALIZER;
66
67 /* protects authdes cache (svcauth_des.c) */
68 mutex_t authdes_lock = MUTEX_INITIALIZER;
69 /* auth_none.c serialization */
70 mutex_t authnone_lock = MUTEX_INITIALIZER;
71 /* protects the Auths list (svc_auth.c) */
72 mutex_t authsvc_lock = MUTEX_INITIALIZER;
73 /* protects client-side fd lock array */
74 mutex_t clnt_fd_lock = MUTEX_INITIALIZER;
75 /* clnt_raw.c serialization */
76 mutex_t clntraw_lock = MUTEX_INITIALIZER;
77 /* domainname and domain_fd (getdname.c) and default_domain (rpcdname.c) */
78 mutex_t dname_lock = MUTEX_INITIALIZER;
79 /* dupreq variables (svc_dg.c) */
80 mutex_t dupreq_lock = MUTEX_INITIALIZER;
81 /* protects first_time and hostname (key_call.c) */
82 mutex_t keyserv_lock = MUTEX_INITIALIZER;
83 /* serializes rpc_trace() (rpc_trace.c) */
84 mutex_t libnsl_trace_lock = MUTEX_INITIALIZER;
85 /* loopnconf (rpcb_clnt.c) */
86 mutex_t loopnconf_lock = MUTEX_INITIALIZER;
87 /* serializes ops initializations */
88 mutex_t ops_lock = MUTEX_INITIALIZER;
89 /* protects ``port'' static in bindresvport() */
90 mutex_t portnum_lock = MUTEX_INITIALIZER;
91 /* protects proglst list (svc_simple.c) */
92 mutex_t proglst_lock = MUTEX_INITIALIZER;
93 /* serializes clnt_com_create() (rpc_soc.c) */
94 mutex_t rpcsoc_lock = MUTEX_INITIALIZER;
95 /* svc_raw.c serialization */
96 mutex_t svcraw_lock = MUTEX_INITIALIZER;
97 /* xprtlist (svc_generic.c) */
98 mutex_t xprtlist_lock = MUTEX_INITIALIZER;
99 /* serializes calls to public key routines */
100 mutex_t serialize_pkey = MUTEX_INITIALIZER;
101
102 #endif /* _REENTRANT */
103
104
105 #undef rpc_createerr
106
107 struct rpc_createerr rpc_createerr;
108
109 #ifdef _REENTRANT
110 static thread_key_t rce_key;
111 static once_t rce_once = ONCE_INITIALIZER;
112
113 static void
114 __rpc_createerr_setup(void)
115 {
116
117 thr_keycreate(&rce_key, free);
118 }
119 #endif /* _REENTRANT */
120
121 struct rpc_createerr*
122 __rpc_createerr()
123 {
124 #ifdef _REENTRANT
125 struct rpc_createerr *rce_addr = 0;
126 extern int __isthreaded;
127
128 if (__isthreaded == 0)
129 return (&rpc_createerr);
130 thr_once(&rce_once, __rpc_createerr_setup);
131 rce_addr = thr_getspecific(rce_key);
132 if (rce_addr == NULL) {
133 rce_addr = malloc(sizeof(*rce_addr));
134 if (rce_addr == NULL)
135 return &rpc_createerr;
136 thr_setspecific(rce_key, (void *) rce_addr);
137 memset(rce_addr, 0, sizeof (struct rpc_createerr));
138 }
139
140 return (rce_addr);
141 #else
142 return &rpc_createerr;
143 #endif
144 }
145
146