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