From 3b8bef73afd6ecba0a9f9c7ba1cfa487907d5ea5 Mon Sep 17 00:00:00 2001
From: Tim Wickberg <tim@schedmd.com>
Date: Tue, 14 Jun 2016 17:38:59 +0200
Subject: [PATCH] Revert "Fix hostrange_hn_within to allow for mixed prefix
 lengths."

This reverts commit 7843e158e014d0be0c7e598faba3399140d71527.

Conflicts:
	NEWS
---
 NEWS                  |  2 --
 src/common/hostlist.c | 61 ++++++++++++++++++++-----------------------
 2 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/NEWS b/NEWS
index 147a23bab43..a00296a207e 100644
--- a/NEWS
+++ b/NEWS
@@ -8,8 +8,6 @@ documents those changes that are of interest to users and administrators.
  -- Documentation - cleanup typos.
  -- Add logic so that slurmstepd can be launched under valgrind.
  -- Increase buffer size to read /proc/*/stat files.
- -- Fix hostrange_hn_within to allow hostname lookup within a set of nodes
-    with different length prefixes.
  -- MYSQL - Handle ER_HOST_IS_BLOCKED better by failing when it occurs instead
     of continuously printing the message over and over as the problem will
     most likely not resolve itself.
diff --git a/src/common/hostlist.c b/src/common/hostlist.c
index 7cc505828f0..afda8418a22 100644
--- a/src/common/hostlist.c
+++ b/src/common/hostlist.c
@@ -78,7 +78,6 @@
 #include "src/common/working_cluster.h"
 #include "src/common/xassert.h"
 #include "src/common/xmalloc.h"
-#include "src/common/xstring.h"
 
 /*
  * Define slurm-specific aliases for use by plugins, see slurm_xlator.h
@@ -374,7 +373,7 @@ static char *        hostrange_pop(hostrange_t);
 static char *        hostrange_shift(hostrange_t, int);
 static int           hostrange_join(hostrange_t, hostrange_t);
 static hostrange_t   hostrange_intersect(hostrange_t, hostrange_t);
-static bool          _hostrange_hn_within(const hostrange_t, const hostname_t);
+static int           hostrange_hn_within(hostrange_t, hostname_t);
 static size_t        hostrange_to_string(hostrange_t hr, size_t, char *,
 					 char *, int);
 static size_t        hostrange_numstr(hostrange_t, size_t, char *, int);
@@ -1104,12 +1103,11 @@ static hostrange_t hostrange_intersect(hostrange_t h1, hostrange_t h2)
 	return new;
 }
 
-/* return true if hostname hn is within the hostrange hr */
-static bool _hostrange_hn_within(const hostrange_t hr, const hostname_t hn)
+/* return 1 if hostname hn is within the hostrange hr
+ *        0 if not.
+ */
+static int hostrange_hn_within(hostrange_t hr, hostname_t hn)
 {
-	hostname_t hn_tmp;
-	int retval = false;
-
 	if (hr->singlehost) {
 		/*
 		 *  If the current hostrange [hr] is a `singlehost' (no valid
@@ -1120,7 +1118,10 @@ static bool _hostrange_hn_within(const hostrange_t hr, const hostname_t hn)
 		 *   which case we return true. Otherwise, there is no
 		 *   possibility that [hn] matches [hr].
 		 */
-		return !xstrcmp(hn->hostname, hr->prefix);
+		if (strcmp (hn->hostname, hr->prefix) == 0)
+			return 1;
+		else
+			return 0;
 	}
 
 	/*
@@ -1128,20 +1129,19 @@ static bool _hostrange_hn_within(const hostrange_t hr, const hostname_t hn)
 	 *   better have a valid numeric suffix, or there is no
 	 *   way we can match
 	 */
-	if (!hostname_suffix_is_valid(hn))
-		return false;
+	if (!hostname_suffix_is_valid (hn))
+		return 0;
 
 	/*
 	 *  If hostrange and hostname prefixes don't match, then
 	 *   there is way the hostname falls within the range [hr].
 	 */
-	hn_tmp = hostname_create(hn->hostname);
-	if (xstrcmp(hr->prefix, hn->prefix) != 0) {
+	if (strcmp(hr->prefix, hn->prefix) != 0) {
 		int len1, len2, ldiff;
 		int dims = slurmdb_setup_cluster_name_dims();
 
 		if (dims != 1)
-			goto done;
+			return 0;
 
 		/* Below logic was added since primarily for a cray
 		 * where people typically drop
@@ -1162,14 +1162,14 @@ static bool _hostrange_hn_within(const hostrange_t hr, const hostname_t hn)
 		ldiff = len1 - len2;
 
 		if (ldiff > 0 && isdigit(hr->prefix[len1-1])
-		    && (strlen(hn_tmp->suffix) >= ldiff)) {
+		    && (strlen(hn->suffix) >= ldiff)) {
 			/* Tack on ldiff of the hostname's suffix to that of
 			 * it's prefix */
 			hn->prefix = realloc(hn->prefix, len2+ldiff+1);
-			strncat(hn_tmp->prefix, hn_tmp->suffix, ldiff);
+			strncat(hn->prefix, hn->suffix, ldiff);
 			/* Now adjust the suffix of the hostname object. */
-			hn_tmp->suffix += ldiff;
-			/* And the numeric representation just in case
+			hn->suffix += ldiff;
+			/* And the numeric representation just incase
 			 * whatever we just tacked on to the prefix
 			 * had something other than 0 in it.
 			 *
@@ -1177,29 +1177,26 @@ static bool _hostrange_hn_within(const hostrange_t hr, const hostname_t hn)
 			 * single dimension systems we will always use
 			 * the base 10.
 			 */
-			hn_tmp->num = strtoul(hn_tmp->suffix, NULL, 10);
+			hn->num = strtoul(hn->suffix, NULL, 10);
 
 			/* Now compare them and see if they match */
-			if (xstrcmp(hr->prefix, hn_tmp->prefix) != 0)
-				goto done;
-		} else {
-			goto done;
-		}
+			if (strcmp(hr->prefix, hn->prefix) != 0)
+				return 0;
+		} else
+			return 0;
 	}
 
 	/*
 	 *  Finally, check whether [hn], with a valid numeric suffix,
 	 *   falls within the range of [hr].
 	 */
-	if (hn_tmp->num <= hr->hi && hn_tmp->num >= hr->lo) {
-		int width = hostname_suffix_width(hn_tmp);
-		int num = hn_tmp->num;
-		retval = _width_equiv(hr->lo, &hr->width, num, &width);
+	if (hn->num <= hr->hi && hn->num >= hr->lo) {
+		int width = hostname_suffix_width(hn);
+		int num = hn->num;
+		return (_width_equiv(hr->lo, &hr->width, num, &width));
 	}
 
-done:
-	hostname_destroy(hn_tmp);
-	return retval;
+	return 0;
 }
 
 
@@ -2447,7 +2444,7 @@ int hostlist_find(hostlist_t hl, const char *hostname)
 	LOCK_HOSTLIST(hl);
 
 	for (i = 0, count = 0; i < hl->nranges; i++) {
-		if (_hostrange_hn_within(hl->hr[i], hn)) {
+		if (hostrange_hn_within(hl->hr[i], hn)) {
 			if (hostname_suffix_is_valid(hn))
 				ret = count + hn->num - hl->hr[i]->lo;
 			else
@@ -3669,7 +3666,7 @@ static int hostset_find_host(hostset_t set, const char *host)
 	LOCK_HOSTLIST(set->hl);
 	hn = hostname_create(host);
 	for (i = 0; i < set->hl->nranges; i++) {
-		if (_hostrange_hn_within(set->hl->hr[i], hn)) {
+		if (hostrange_hn_within(set->hl->hr[i], hn)) {
 			retval = 1;
 			goto done;
 		}
-- 
GitLab