Home | History | Annotate | Line # | Download | only in rpc
mt_misc.c revision 1.4
      1 /*	$NetBSD: mt_misc.c,v 1.4 2004/05/28 14:39:07 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.4 2004/05/28 14:39:07 christos Exp $");
     49 #endif
     50 
     51 #include	"reentrant.h"
     52 #include	<rpc/rpc.h>
     53 #include	<sys/time.h>
     54 #include	<stdlib.h>
     55 #include	<string.h>
     56 
     57 #ifdef _REENTRANT
     58 
     59 /* protects the services list (svc.c) */
     60 rwlock_t	svc_lock = RWLOCK_INITIALIZER;
     61 /* protects svc_fdset and the xports[] array */
     62 rwlock_t	svc_fd_lock = RWLOCK_INITIALIZER;
     63 /* protects the RPCBIND address cache */
     64 rwlock_t	rpcbaddr_cache_lock = RWLOCK_INITIALIZER;
     65 
     66 /* protects authdes cache (svcauth_des.c) */
     67 mutex_t	authdes_lock = MUTEX_INITIALIZER;
     68 /* auth_none.c serialization */
     69 mutex_t	authnone_lock = MUTEX_INITIALIZER;
     70 /* protects the Auths list (svc_auth.c) */
     71 mutex_t	authsvc_lock = MUTEX_INITIALIZER;
     72 /* protects client-side fd lock array */
     73 mutex_t	clnt_fd_lock = MUTEX_INITIALIZER;
     74 /* clnt_raw.c serialization */
     75 mutex_t	clntraw_lock = MUTEX_INITIALIZER;
     76 /* domainname and domain_fd (getdname.c) and default_domain (rpcdname.c) */
     77 mutex_t	dname_lock = MUTEX_INITIALIZER;
     78 /* dupreq variables (svc_dg.c) */
     79 mutex_t	dupreq_lock = MUTEX_INITIALIZER;
     80 /* protects first_time and hostname (key_call.c) */
     81 mutex_t	keyserv_lock = MUTEX_INITIALIZER;
     82 /* serializes rpc_trace() (rpc_trace.c) */
     83 mutex_t	libnsl_trace_lock = MUTEX_INITIALIZER;
     84 /* loopnconf (rpcb_clnt.c) */
     85 mutex_t	loopnconf_lock = MUTEX_INITIALIZER;
     86 /* serializes ops initializations */
     87 mutex_t	ops_lock = MUTEX_INITIALIZER;
     88 /* protects ``port'' static in bindresvport() */
     89 mutex_t	portnum_lock = MUTEX_INITIALIZER;
     90 /* protects proglst list (svc_simple.c) */
     91 mutex_t	proglst_lock = MUTEX_INITIALIZER;
     92 /* serializes clnt_com_create() (rpc_soc.c) */
     93 mutex_t	rpcsoc_lock = MUTEX_INITIALIZER;
     94 /* svc_raw.c serialization */
     95 mutex_t	svcraw_lock = MUTEX_INITIALIZER;
     96 /* xprtlist (svc_generic.c) */
     97 mutex_t	xprtlist_lock = MUTEX_INITIALIZER;
     98 /* serializes calls to public key routines */
     99 mutex_t serialize_pkey = MUTEX_INITIALIZER;
    100 
    101 #endif /* _REENTRANT */
    102 
    103 
    104 #undef	rpc_createerr
    105 
    106 struct rpc_createerr rpc_createerr;
    107 
    108 #ifdef _REENTRANT
    109 static thread_key_t rce_key;
    110 static once_t rce_once = ONCE_INITIALIZER;
    111 
    112 static void
    113 __rpc_createerr_setup(void)
    114 {
    115 
    116 	thr_keycreate(&rce_key, free);
    117 }
    118 #endif /* _REENTRANT */
    119 
    120 struct rpc_createerr*
    121 __rpc_createerr()
    122 {
    123 #ifdef _REENTRANT
    124 	struct rpc_createerr *rce_addr = 0;
    125 	extern int __isthreaded;
    126 
    127 	if (__isthreaded == 0)
    128 		return (&rpc_createerr);
    129 	thr_once(&rce_once, __rpc_createerr_setup);
    130 	rce_addr = thr_getspecific(rce_key);
    131 	if (rce_addr == NULL) {
    132 		rce_addr = (struct rpc_createerr *)
    133 		    malloc(sizeof (struct rpc_createerr));
    134 		thr_setspecific(rce_key, (void *) rce_addr);
    135 		memset(rce_addr, 0, sizeof (struct rpc_createerr));
    136 	}
    137 
    138 	return (rce_addr);
    139 #else
    140 	return &rpc_createerr;
    141 #endif
    142 }
    143 
    144