[sheepdog] [PATCH 12/14] sheep: make node_to_str and lnode_to_str thread-safe

MORITA Kazutaka morita.kazutaka at gmail.com
Sat Aug 10 17:58:53 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheep.h       |    4 ++--
 sheep/cluster/local.c |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/sheep.h b/include/sheep.h
index 219add9..7a98ce7 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -315,9 +315,9 @@ static inline int nodes_to_vnodes(struct sd_node *nodes, int nr,
 
 #define MAX_NODE_STR_LEN 256
 
-static inline char *node_to_str(const struct sd_node *id)
+static inline const char *node_to_str(const struct sd_node *id)
 {
-	static char str[MAX_NODE_STR_LEN];
+	static __thread char str[MAX_NODE_STR_LEN];
 	int af = AF_INET6;
 	const uint8_t *addr = id->nid.addr;
 
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 4350ca2..b4adf87 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -40,11 +40,11 @@ struct local_node {
 	bool gateway;
 };
 
-static char *lnode_to_str(struct local_node *lnode)
+static const char *lnode_to_str(struct local_node *lnode)
 {
-	char *s = node_to_str(&lnode->node);
+	static __thread char s[MAX_NODE_STR_LEN + 32];
 
-	snprintf(s + strlen(s), MAX_NODE_STR_LEN - strlen(s), " pid:%d",
+	snprintf(s, sizeof(s), "%s pid:%d", node_to_str(&lnode->node),
 		 lnode->pid);
 
 	return s;
-- 
1.7.9.5




More information about the sheepdog mailing list