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