[PATCH] ctdb: strip trailing spaces from nodes file lines

Michael Adam obnox at samba.org
Fri Jun 26 09:03:52 MDT 2015


Apparently this would be appreciated by some users.

Review/push appreciated.

Thanks - Michael
-------------- next part --------------
From eae2f0b7872e95c6ac7fc45c370f08812160bac3 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 26 Jun 2015 16:24:55 +0200
Subject: [PATCH] ctdb: strip trailing spaces from nodes file.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 ctdb/common/ctdb_util.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index 5d63c27..709c7a1 100644
--- a/ctdb/common/ctdb_util.c
+++ b/ctdb/common/ctdb_util.c
@@ -548,15 +548,26 @@ struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
 	}
 
 	for (i=0; i < nlines; i++) {
-		const char *node;
+		char *node;
 		uint32_t flags;
+		size_t len;
 
 		node = lines[i];
 		/* strip leading spaces */
 		while((*node == ' ') || (*node == '\t')) {
 			node++;
 		}
-		if (strcmp(node, "") == 0) {
+
+		len = strlen(node);
+
+		while ((len > 1) &&
+		       ((node[len-1] == ' ') || (node[len-1] == '\t')))
+		{
+			node[len-1] = '\0';
+			len--;
+		}
+
+		if (len == 0) {
 			continue;
 		}
 		if (*node == '#') {
@@ -566,7 +577,7 @@ struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
 			   would cause subsequent nodes to change
 			   their PNN. */
 			flags = NODE_FLAGS_DELETED;
-			node = "0.0.0.0";
+			node = discard_const("0.0.0.0");
 		} else {
 			flags = 0;
 		}
-- 
2.4.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150626/ee4a1bdf/attachment.pgp>


More information about the samba-technical mailing list