xref: /minix3/lib/libc/rpc/mt_misc.c (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc /*	$NetBSD: mt_misc.c,v 1.9 2012/03/20 17:14:50 matt Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*-
42fe8fb19SBen Gras  * Copyright (c) 2004 The NetBSD Foundation, Inc.
52fe8fb19SBen Gras  * All rights reserved.
62fe8fb19SBen Gras  *
72fe8fb19SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
82fe8fb19SBen Gras  * by Frank van der Linden.
92fe8fb19SBen Gras  *
102fe8fb19SBen Gras  * Redistribution and use in source and binary forms, with or without
112fe8fb19SBen Gras  * modification, are permitted provided that the following conditions
122fe8fb19SBen Gras  * are met:
132fe8fb19SBen Gras  * 1. Redistributions of source code must retain the above copyright
142fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer.
152fe8fb19SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
162fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer in the
172fe8fb19SBen Gras  *    documentation and/or other materials provided with the distribution.
182fe8fb19SBen Gras  *
192fe8fb19SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
202fe8fb19SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
212fe8fb19SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
222fe8fb19SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
232fe8fb19SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
242fe8fb19SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
252fe8fb19SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
262fe8fb19SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
272fe8fb19SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
282fe8fb19SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
292fe8fb19SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
302fe8fb19SBen Gras  */
312fe8fb19SBen Gras 
322fe8fb19SBen Gras /*
332fe8fb19SBen Gras  *	Define and initialize MT data for libnsl.
342fe8fb19SBen Gras  *	The _libnsl_lock_init() function below is the library's .init handler.
352fe8fb19SBen Gras  */
362fe8fb19SBen Gras 
372fe8fb19SBen Gras /* #pragma ident	"@(#)mt_misc.c	1.24	93/04/29 SMI" */
382fe8fb19SBen Gras 
392fe8fb19SBen Gras #include <sys/cdefs.h>
402fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
41*f14fb602SLionel Sambuc __RCSID("$NetBSD: mt_misc.c,v 1.9 2012/03/20 17:14:50 matt Exp $");
422fe8fb19SBen Gras #endif
432fe8fb19SBen Gras 
442fe8fb19SBen Gras #include	"namespace.h"
452fe8fb19SBen Gras #include	"reentrant.h"
462fe8fb19SBen Gras #include	<rpc/rpc.h>
472fe8fb19SBen Gras #include	<sys/time.h>
482fe8fb19SBen Gras #include	<stdlib.h>
492fe8fb19SBen Gras #include	<string.h>
502fe8fb19SBen Gras 
512fe8fb19SBen Gras #ifdef _REENTRANT
522fe8fb19SBen Gras 
532fe8fb19SBen Gras /* protects the services list (svc.c) */
542fe8fb19SBen Gras rwlock_t	svc_lock = RWLOCK_INITIALIZER;
552fe8fb19SBen Gras /* protects svc_fdset and the xports[] array */
562fe8fb19SBen Gras rwlock_t	svc_fd_lock = RWLOCK_INITIALIZER;
572fe8fb19SBen Gras /* protects the RPCBIND address cache */
582fe8fb19SBen Gras rwlock_t	rpcbaddr_cache_lock = RWLOCK_INITIALIZER;
592fe8fb19SBen Gras 
602fe8fb19SBen Gras /* protects authdes cache (svcauth_des.c) */
612fe8fb19SBen Gras mutex_t	authdes_lock = MUTEX_INITIALIZER;
622fe8fb19SBen Gras /* auth_none.c serialization */
632fe8fb19SBen Gras mutex_t	authnone_lock = MUTEX_INITIALIZER;
642fe8fb19SBen Gras /* protects the Auths list (svc_auth.c) */
652fe8fb19SBen Gras mutex_t	authsvc_lock = MUTEX_INITIALIZER;
662fe8fb19SBen Gras /* protects client-side fd lock array */
672fe8fb19SBen Gras mutex_t	clnt_fd_lock = MUTEX_INITIALIZER;
682fe8fb19SBen Gras /* clnt_raw.c serialization */
692fe8fb19SBen Gras mutex_t	clntraw_lock = MUTEX_INITIALIZER;
702fe8fb19SBen Gras /* domainname and domain_fd (getdname.c) and default_domain (rpcdname.c) */
712fe8fb19SBen Gras mutex_t	dname_lock = MUTEX_INITIALIZER;
722fe8fb19SBen Gras /* dupreq variables (svc_dg.c) */
732fe8fb19SBen Gras mutex_t	dupreq_lock = MUTEX_INITIALIZER;
742fe8fb19SBen Gras /* protects first_time and hostname (key_call.c) */
752fe8fb19SBen Gras mutex_t	keyserv_lock = MUTEX_INITIALIZER;
762fe8fb19SBen Gras /* serializes rpc_trace() (rpc_trace.c) */
772fe8fb19SBen Gras mutex_t	libnsl_trace_lock = MUTEX_INITIALIZER;
782fe8fb19SBen Gras /* loopnconf (rpcb_clnt.c) */
792fe8fb19SBen Gras mutex_t	loopnconf_lock = MUTEX_INITIALIZER;
802fe8fb19SBen Gras /* serializes ops initializations */
812fe8fb19SBen Gras mutex_t	ops_lock = MUTEX_INITIALIZER;
822fe8fb19SBen Gras /* protects ``port'' static in bindresvport() */
832fe8fb19SBen Gras mutex_t	portnum_lock = MUTEX_INITIALIZER;
842fe8fb19SBen Gras /* protects proglst list (svc_simple.c) */
852fe8fb19SBen Gras mutex_t	proglst_lock = MUTEX_INITIALIZER;
862fe8fb19SBen Gras /* serializes clnt_com_create() (rpc_soc.c) */
872fe8fb19SBen Gras mutex_t	rpcsoc_lock = MUTEX_INITIALIZER;
882fe8fb19SBen Gras /* svc_raw.c serialization */
892fe8fb19SBen Gras mutex_t	svcraw_lock = MUTEX_INITIALIZER;
902fe8fb19SBen Gras /* xprtlist (svc_generic.c) */
912fe8fb19SBen Gras mutex_t	xprtlist_lock = MUTEX_INITIALIZER;
922fe8fb19SBen Gras /* serializes calls to public key routines */
932fe8fb19SBen Gras mutex_t serialize_pkey = MUTEX_INITIALIZER;
942fe8fb19SBen Gras 
952fe8fb19SBen Gras #endif /* _REENTRANT */
962fe8fb19SBen Gras 
972fe8fb19SBen Gras 
982fe8fb19SBen Gras #undef	rpc_createerr
992fe8fb19SBen Gras 
1002fe8fb19SBen Gras struct rpc_createerr rpc_createerr;
1012fe8fb19SBen Gras 
1022fe8fb19SBen Gras #ifdef _REENTRANT
1032fe8fb19SBen Gras static thread_key_t rce_key;
1042fe8fb19SBen Gras static once_t rce_once = ONCE_INITIALIZER;
1052fe8fb19SBen Gras 
1062fe8fb19SBen Gras static void
__rpc_createerr_setup(void)1072fe8fb19SBen Gras __rpc_createerr_setup(void)
1082fe8fb19SBen Gras {
1092fe8fb19SBen Gras 
1102fe8fb19SBen Gras 	thr_keycreate(&rce_key, free);
1112fe8fb19SBen Gras }
1122fe8fb19SBen Gras #endif /* _REENTRANT */
1132fe8fb19SBen Gras 
1142fe8fb19SBen Gras struct rpc_createerr*
__rpc_createerr(void)115*f14fb602SLionel Sambuc __rpc_createerr(void)
1162fe8fb19SBen Gras {
1172fe8fb19SBen Gras #ifdef _REENTRANT
1182fe8fb19SBen Gras 	struct rpc_createerr *rce_addr = 0;
1192fe8fb19SBen Gras 
1202fe8fb19SBen Gras 	if (__isthreaded == 0)
1212fe8fb19SBen Gras 		return (&rpc_createerr);
1222fe8fb19SBen Gras 	thr_once(&rce_once, __rpc_createerr_setup);
1232fe8fb19SBen Gras 	rce_addr = thr_getspecific(rce_key);
1242fe8fb19SBen Gras 	if (rce_addr == NULL) {
1252fe8fb19SBen Gras 		rce_addr = malloc(sizeof(*rce_addr));
1262fe8fb19SBen Gras 		if (rce_addr == NULL)
1272fe8fb19SBen Gras 			return &rpc_createerr;
1282fe8fb19SBen Gras 		thr_setspecific(rce_key, (void *) rce_addr);
1292fe8fb19SBen Gras 		memset(rce_addr, 0, sizeof (struct rpc_createerr));
1302fe8fb19SBen Gras 	}
1312fe8fb19SBen Gras 
1322fe8fb19SBen Gras 	return (rce_addr);
1332fe8fb19SBen Gras #else
1342fe8fb19SBen Gras 	return &rpc_createerr;
1352fe8fb19SBen Gras #endif
1362fe8fb19SBen Gras }
137