Commit d1a02341 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

Remove caching wrapper for gethostname.

This was added for terrible systems that rely on a slow DNS server to
look up the local hostname.  Most OSs do a much better job setting
local host names in the local /etc/hosts file today.  Even if they
don't, we no longer do a large number of lookups anymore, so this
should not be a problem.
parent ba6b5046
......@@ -553,7 +553,6 @@ HYD_status HYDU_create_process(char **client_arg, struct HYD_env *env_list,
/* others */
int HYDU_dceil(int x, int y);
HYD_status HYDU_add_to_node_list(const char *hostname, int num_procs, struct HYD_node **node_list);
HYD_status HYDU_gethostname(char *hostname);
void HYDU_delay(unsigned long delay);
/* signals */
......
......@@ -184,8 +184,8 @@ int main(int argc, char **argv)
char localhost[MAX_HOSTNAME_LEN] = { 0 };
/* The RMK didn't give us anything back; use localhost */
status = HYDU_gethostname(localhost);
HYDU_ERR_POP(status, "unable to get local hostname\n");
if (gethostname(localhost, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local hostname\n");
status = HYDU_add_to_node_list(localhost, 1, &HYD_server_info.node_list);
HYDU_ERR_POP(status, "unable to add to node list\n");
......@@ -293,8 +293,8 @@ int main(int argc, char **argv)
HYD_server_info.localhost = HYDU_strdup(node->hostname);
else {
HYDU_MALLOC(HYD_server_info.localhost, char *, MAX_HOSTNAME_LEN, status);
status = HYDU_gethostname(HYD_server_info.localhost);
HYDU_ERR_POP(status, "unable to get local hostname\n");
if (gethostname(HYD_server_info.localhost, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local hostname\n");
}
}
......
......@@ -336,8 +336,8 @@ static HYD_status mfile_fn(char *arg, char ***argv)
HYDU_ERR_POP(status, "error parsing hostfile\n");
}
else {
status = HYDU_gethostname(localhost);
HYDU_ERR_POP(status, "unable to get local hostname\n");
if (gethostname(localhost, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local hostname\n");
status = HYDU_add_to_node_list(localhost, 1, &HYD_server_info.node_list);
HYDU_ERR_POP(status, "unable to add to node list\n");
......
......@@ -15,8 +15,8 @@ HYD_status HYDU_dbg_init(const char *str)
HYDU_mem_init();
status = HYDU_gethostname(hostname);
HYDU_ERR_POP(status, "unable to get local host name\n");
if (gethostname(hostname, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local host name\n");
HYDU_MALLOC(HYD_dbg_prefix, char *, strlen(hostname) + 1 + strlen(str) + 1, status);
HYDU_snprintf(HYD_dbg_prefix, strlen(hostname) + 1 + strlen(str) + 1, "%s@%s", str, hostname);
......
......@@ -58,34 +58,6 @@ HYD_status HYDU_add_to_node_list(const char *hostname, int num_procs, struct HYD
goto fn_exit;
}
/* This function just adds a simple caching logic to gethostname to
* avoid hitting the DNS too many times */
HYD_status HYDU_gethostname(char *hostname)
{
static char localhost[MAX_HOSTNAME_LEN] = { 0 };
HYD_status status = HYD_SUCCESS;
HYDU_FUNC_ENTER();
if (strcmp(localhost, "")) {
HYDU_snprintf(hostname, MAX_HOSTNAME_LEN, "%s", localhost);
goto fn_exit;
}
if (gethostname(hostname, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR,
"gethostname error (hostname: %s; errno: %d)\n", hostname, errno);
HYDU_snprintf(localhost, MAX_HOSTNAME_LEN, "%s", hostname);
fn_exit:
HYDU_FUNC_EXIT();
return status;
fn_fail:
goto fn_exit;
}
void HYDU_delay(unsigned long delay)
{
struct timeval start, end;
......
......@@ -164,8 +164,8 @@ HYD_status HYDU_sock_connect(const char *host, uint16_t port, int *fd, int retri
if (ret < 0) {
char localhost[MAX_HOSTNAME_LEN] = { 0 };
status = HYDU_gethostname(localhost);
HYDU_ERR_POP(status, "unable to get local hostname\n");
if (gethostname(localhost, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local hostname\n");
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR,
"unable to connect from \"%s\" to \"%s\" (%s)\n",
......@@ -649,8 +649,8 @@ HYDU_sock_create_and_listen_portstr(char *iface, char *hostname, char *port_rang
else {
char localhost[MAX_HOSTNAME_LEN] = { 0 };
status = HYDU_gethostname(localhost);
HYDU_ERR_POP(status, "unable to get local hostname\n");
if (gethostname(localhost, MAX_HOSTNAME_LEN) < 0)
HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR, "unable to get local hostname\n");
ip = HYDU_strdup(localhost);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment