FreeBSD/usr.sbin/mountd/mountd.c
/*
 * Called after all the create_service() calls have succeeded, to complete
 * the setup and registration.
 */
Called after all the create_service() calls have succeeded, to complete
the setup and registration.
Called after all the create_service () calls have succeeded to complete the setup and registration .
static void
complete_service(struct netconfig *nconf, char *port_str)
{
	struct addrinfo hints, *res = NULL;
	struct __rpc_sockinfo si;
	struct netbuf servaddr;
	SVCXPRT	*transp = NULL;
	int aicode, fd, nhostsbak;
	int registered = 0;
	if ((nconf->nc_semantics != NC_TPI_CLTS) &&
	    (nconf->nc_semantics != NC_TPI_COTS) &&
	    (nconf->nc_semantics != NC_TPI_COTS_ORD))
		return;	
	if (!__rpc_nconf2sockinfo(nconf, &si)) {
		syslog(LOG_ERR, "cannot get information for %s",
		    nconf->nc_netid);
		return;
	}
	nhostsbak = nhosts;
	while (nhostsbak > 0) {
		--nhostsbak;
		if (sock_fdpos >= sock_fdcnt) {
			syslog(LOG_ERR, "Ran out of socket fd's");
			return;
		}
		fd = sock_fd[sock_fdpos++];
		if (fd < 0)
			continue;
		if (nconf->nc_semantics != NC_TPI_CLTS)
			listen(fd, SOMAXCONN);
		if (nconf->nc_semantics == NC_TPI_CLTS )
			transp = svc_dg_create(fd, 0, 0);
		else 
			transp = svc_vc_create(fd, RPC_MAXDATASIZE,
			    RPC_MAXDATASIZE);
		if (transp != (SVCXPRT *) NULL) {
			if (!svc_reg(transp, MOUNTPROG, MOUNTVERS, mntsrv,
			    NULL)) 
				syslog(LOG_ERR,
				    "can't register %s MOUNTVERS service",
				    nconf->nc_netid);
			if (!force_v2) {
				if (!svc_reg(transp, MOUNTPROG, MOUNTVERS3,
				    mntsrv, NULL)) 
					syslog(LOG_ERR,
					    "can't register %s MOUNTVERS3 service",
					    nconf->nc_netid);
			}
		} else 
			syslog(LOG_WARNING, "can't create %s services",
			    nconf->nc_netid);
		if (registered == 0) {
			registered = 1;
			memset(&hints, 0, sizeof hints);
			hints.ai_flags = AI_PASSIVE;
			hints.ai_family = si.si_af;
			hints.ai_socktype = si.si_socktype;
			hints.ai_protocol = si.si_proto;
			if ((aicode = getaddrinfo(NULL, port_str, &hints,
			    &res)) != 0) {
				syslog(LOG_ERR, "cannot get local address: %s",
				    gai_strerror(aicode));
				exit(1);
			}
			servaddr.buf = malloc(res->ai_addrlen);
			memcpy(servaddr.buf, res->ai_addr, res->ai_addrlen);
			servaddr.len = res->ai_addrlen;
			rpcb_set(MOUNTPROG, MOUNTVERS, nconf, &servaddr);
			rpcb_set(MOUNTPROG, MOUNTVERS3, nconf, &servaddr);
			xcreated++;
			freeaddrinfo(res);
		}
	} 
}
static void complete_service ( struct netconfig * nconf , char * port_str ) { struct addrinfo hints , * res = NULL ; struct __rpc_sockinfo si ; struct netbuf servaddr ; SVCXPRT * transp = NULL ; int aicode , fd , nhostsbak ; int registered = 0 ; if ( ( nconf -> nc_semantics != NC_TPI_CLTS ) && ( nconf -> nc_semantics != NC_TPI_COTS ) && ( nconf -> nc_semantics != NC_TPI_COTS_ORD ) ) return ; if ( ! __rpc_nconf2sockinfo ( nconf , & si ) ) { syslog ( LOG_ERR , " " , nconf -> nc_netid ) ; return ; } nhostsbak = nhosts ; while ( nhostsbak > 0 ) { -- nhostsbak ; if ( sock_fdpos >= sock_fdcnt ) { syslog ( LOG_ERR , " " ) ; return ; } fd = sock_fd [ sock_fdpos ++ ] ; if ( fd < 0 ) continue ; if ( nconf -> nc_semantics != NC_TPI_CLTS ) listen ( fd , SOMAXCONN ) ; if ( nconf -> nc_semantics == NC_TPI_CLTS ) transp = svc_dg_create ( fd , 0 , 0 ) ; else transp = svc_vc_create ( fd , RPC_MAXDATASIZE , RPC_MAXDATASIZE ) ; if ( transp != ( SVCXPRT * ) NULL ) { if ( ! svc_reg ( transp , MOUNTPROG , MOUNTVERS , mntsrv , NULL ) ) syslog ( LOG_ERR , " " , nconf -> nc_netid ) ; if ( ! force_v2 ) { if ( ! svc_reg ( transp , MOUNTPROG , MOUNTVERS3 , mntsrv , NULL ) ) syslog ( LOG_ERR , " " , nconf -> nc_netid ) ; } } else syslog ( LOG_WARNING , " " , nconf -> nc_netid ) ; if ( registered == 0 ) { registered = 1 ; memset ( & hints , 0 , sizeof hints ) ; hints . ai_flags = AI_PASSIVE ; hints . ai_family = si . si_af ; hints . ai_socktype = si . si_socktype ; hints . ai_protocol = si . si_proto ; if ( ( aicode = getaddrinfo ( NULL , port_str , & hints , & res ) ) != 0 ) { syslog ( LOG_ERR , " " , gai_strerror ( aicode ) ) ; exit ( 1 ) ; } servaddr . buf = malloc ( res -> ai_addrlen ) ; memcpy ( servaddr . buf , res -> ai_addr , res -> ai_addrlen ) ; servaddr . len = res -> ai_addrlen ; rpcb_set ( MOUNTPROG , MOUNTVERS , nconf , & servaddr ) ; rpcb_set ( MOUNTPROG , MOUNTVERS3 , nconf , & servaddr ) ; xcreated ++ ; freeaddrinfo ( res ) ; } } }
Called after all the create_service() calls have succeeded, to complete
 the setup and registration.
Called after all the create_service () calls have succeeded to complete the setup and registration .
/* not my type */ /*
	 * XXX - using RPC library internal functions.
	 */ /* Should never happen. */ /* end while */