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