From c2b76625ca8ecd1ef68ba0c922f49465600d2442 Mon Sep 17 00:00:00 2001 From: Pavan Balaji Date: Thu, 6 Feb 2014 22:07:00 -0600 Subject: [PATCH] Improve localhost detection. When compiled with strict we completely disable local host detection. In the case where no host is specified, we use the local host name that we get using gethostname. However, when we try to detect if that is the local host, we do not even attempt to do a simple gethostname check. Thanks to Orion Poplawski for reporting the problem and a detailed analysis of the issue. --- src/pm/hydra/utils/sock/sock.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pm/hydra/utils/sock/sock.c b/src/pm/hydra/utils/sock/sock.c index 56cd7c7e..1a282cb4 100644 --- a/src/pm/hydra/utils/sock/sock.c +++ b/src/pm/hydra/utils/sock/sock.c @@ -608,9 +608,23 @@ HYD_status HYDU_sock_is_local(char *host, int *is_local) #else HYD_status HYDU_sock_is_local(char *host, int *is_local) { + char lhost[MAX_HOSTNAME_LEN]; + HYD_status status = HYD_SUCCESS; + *is_local = 0; - return HYD_SUCCESS; + if (gethostname(lhost, MAX_HOSTNAME_LEN) < 0) { + HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "gethostname returned an error\n"); + } + else if (!strcmp(lhost, host)) { + *is_local = 1; + } + + fn_exit: + return status; + + fn_fail: + goto fn_exit; } #endif /* HAVE_GETIFADDRS && HAVE_INET_NTOP */ -- 1.8.3.4 (Apple Git-47)