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