/* * If we find SENS resolver, use the functions found there, i.e. * resolvGetHostByName() and resolvGetHostByAddr(). Otherwise we use * our own, which are just wrappers around hostGetByName() and * hostGetByAddr(). Here we look up the functions. */ void ei_init_resolve(void) { #ifdef VXWORKS void *sym; SYM_TYPE symtype; if (symFindByName(sysSymTbl,"resolvGetHostByName", (char **)&sym,&symtype) == OK && verify_dns_configuration()) { sens_gethostbyname = sym; DEBUGF((stderr,"found SENS resolver - using it for gethostbyname()\n")); if (symFindByName(sysSymTbl,"resolvGetHostByAddr", (char **)&sym,&symtype) == OK) { sens_gethostbyaddr = sym; DEBUGF((stderr,"found SENS resolver - " "using it for gethostbyaddr()\n")); } else { DEBUGF((stderr,"SENS resolver not found - " "using default gethostbyaddr()\n")); } } else { DEBUGF((stderr,"SENS resolver not found - " "using default gethostbyname()\n")); } #endif /* VXWORKS */ #ifdef _REENTRANT ei_gethost_sem = ei_mutex_create(); #endif /* _REENTRANT */ ei_resolve_initialized = 1; }
int erl_init_eterm_alloc (void) { #if defined(PURIFY) && defined (DEBUG) fprintf(stderr,"erl_fix_alloc() compiled for Purify - using \"real\" malloc()"); #endif erl_eterm_state = malloc(sizeof(*erl_eterm_state)); if (erl_eterm_state == NULL) goto err1; erl_eterm_state->freelist = NULL; erl_eterm_state->freed = 0; erl_eterm_state->allocated = 0; #ifdef _REENTRANT erl_eterm_state->lock = ei_mutex_create(); if (erl_eterm_state->lock == NULL) goto err2; #endif /* _REENTRANT */ return 1; /* Error cleanup */ #ifdef _REENTRANT err2: /* FIXME ENOMEM is not what went wrong... */ free(erl_eterm_state); #endif /* _REENTRANT */ err1: erl_errno = ENOMEM; return 0; }
/* * Initialize by set: thishostname, thisalivename, * thisnodename and thisipaddr. At success return 0, * otherwise return -1. */ int ei_connect_init(ei_cnode* ec, const char* this_node_name, const char *cookie, short creation) { struct hostent *hp; char thishostname[EI_MAXHOSTNAMELEN+1]; char thisnodename[MAXNODELEN+1]; char thisalivename[EI_MAXALIVELEN+1]; #ifdef __WIN32__ if (!initWinSock()) { EI_TRACE_ERR0("ei_connect_xinit","can't initiate winsock"); return ERL_ERROR; } #endif /* win32 */ #ifdef _REENTRANT if (ei_sockets_lock == NULL) { ei_sockets_lock = ei_mutex_create(); } #endif /* _REENTRANT */ if (gethostname(thishostname, EI_MAXHOSTNAMELEN) == -1) { #ifdef __WIN32__ EI_TRACE_ERR1("ei_connect_init","Failed to get host name: %d", WSAGetLastError()); #else EI_TRACE_ERR1("ei_connect_init","Failed to get host name: %d", errno); #endif /* win32 */ return ERL_ERROR; } if (this_node_name == NULL) { sprintf(thisalivename, "c%d", (int) getpid()); } else if (strlen(this_node_name) >= sizeof(thisalivename)) { EI_TRACE_ERR0("ei_connect_init","ERROR: this_node_name too long"); return ERL_ERROR; } else { strcpy(thisalivename, this_node_name); } if ((hp = ei_gethostbyname(thishostname)) == 0) { /* Looking up IP given hostname fails. We must be on a standalone host so let's use loopback for communication instead. */ if ((hp = ei_gethostbyname("localhost")) == 0) { #ifdef __WIN32__ char reason[1024]; win32_error(reason,sizeof(reason)); EI_TRACE_ERR2("ei_connect_init", "Can't get ip address for host %s: %s", thishostname, reason); #else EI_TRACE_ERR2("ei_connect_init", "Can't get ip address for host %s: %d", thishostname, h_errno); #endif /* win32 */ return ERL_ERROR; } } { char* ct; if (strcmp(hp->h_name, "localhost") == 0) { /* We use a short node name */ if ((ct = strchr(thishostname, '.')) != NULL) *ct = '\0'; sprintf(thisnodename, "%s@%s", this_node_name, thishostname); } else { /* We use a short node name */ if ((ct = strchr(hp->h_name, '.')) != NULL) *ct = '\0'; strcpy(thishostname, hp->h_name); sprintf(thisnodename, "%s@%s", this_node_name, hp->h_name); } } return ei_connect_xinit(ec, thishostname, thisalivename, thisnodename, (struct in_addr *)*hp->h_addr_list, cookie, creation); }
/* * Perhaps run this routine instead of ei_connect_init/2 ? * Initailize by setting: * thishostname, thisalivename, thisnodename and thisipaddr */ int ei_connect_xinit(ei_cnode* ec, const char *thishostname, const char *thisalivename, const char *thisnodename, Erl_IpAddr thisipaddr, const char *cookie, const short creation) { char *dbglevel; /* FIXME this code was enabled for 'erl'_connect_xinit(), why not here? */ #if 0 #ifdef __WIN32__ if (!initWinSock()) { EI_TRACE_ERR0("ei_connect_xinit","can't initiate winsock"); return ERL_ERROR; } #endif #endif #ifdef _REENTRANT if (ei_sockets_lock == NULL) { ei_sockets_lock = ei_mutex_create(); } #endif /* _REENTRANT */ ec->creation = creation; if (cookie) { if (strlen(cookie) >= sizeof(ec->ei_connect_cookie)) { EI_TRACE_ERR0("ei_connect_xinit", "ERROR: Cookie size too large"); return ERL_ERROR; } else { strcpy(ec->ei_connect_cookie, cookie); } } else if (!get_cookie(ec->ei_connect_cookie, sizeof(ec->ei_connect_cookie))) { return ERL_ERROR; } if (strlen(thishostname) >= sizeof(ec->thishostname)) { EI_TRACE_ERR0("ei_connect_xinit","ERROR: Thishostname too long"); return ERL_ERROR; } strcpy(ec->thishostname, thishostname); if (strlen(thisalivename) >= sizeof(ec->thisalivename)) { EI_TRACE_ERR0("ei_connect_init","Thisalivename too long"); return ERL_ERROR; } strcpy(ec->thisalivename, thisalivename); if (strlen(thisnodename) >= sizeof(ec->thisnodename)) { EI_TRACE_ERR0("ei_connect_init","Thisnodename too long"); return ERL_ERROR; } strcpy(ec->thisnodename, thisnodename); /* FIXME right now this_ipaddr is never used */ /* memmove(&ec->this_ipaddr, thisipaddr, sizeof(ec->this_ipaddr)); */ strcpy(ec->self.node,thisnodename); ec->self.num = 0; ec->self.serial = 0; ec->self.creation = creation; if ((dbglevel = getenv("EI_TRACELEVEL")) != NULL || (dbglevel = getenv("ERL_DEBUG_DIST")) != NULL) ei_tracelevel = atoi(dbglevel); return 0; }