From ab846b9195e0c87ff57d056dbb819b47f6272070 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 25 Jul 2012 15:38:59 -0400 Subject: [PATCH] fixed bugs parsing lustre mount strings. --- amd/ops_lustre.c | 11 +++++++---- include/am_utils.h | 1 + libamu/strutil.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/amd/ops_lustre.c b/amd/ops_lustre.c index 07f117a5..1b321ce4 100644 --- a/amd/ops_lustre.c +++ b/amd/ops_lustre.c @@ -75,7 +75,7 @@ am_ops lustre_ops = static char * lustre_match(am_opts *fo) { - char *xmtab; + char *xmtab, *cp; size_t l; char *rhost, *ptr, *remhost; struct in_addr addr; @@ -96,7 +96,7 @@ lustre_match(am_opts *fo) */ rhost = xstrdup(fo->opt_rhost); remhost = NULL; - for (ptr = strtok(rhost, ","); ptr; ptr = strtok(NULL, ",")) { + for (ptr = strtok(rhost, ":"); ptr; ptr = strtok(NULL, ":")) { char *at = strchr(ptr, '@'); if (at == NULL) { plog(XLOG_USER, "lustre: missing protocol in host `%s'", ptr); @@ -123,10 +123,13 @@ lustre_match(am_opts *fo) memcpy(&addr.s_addr, hp->h_addr, sizeof(addr)); } *at = '@'; + + cp = remhost; if (remhost) - remhost = str3cat(remhost, ",", inet_ntoa(addr), at); + remhost = strvcat(cp, ":", inet_ntoa(addr), at, NULL); else - remhost = str3cat(NULL, inet_ntoa(addr), at, ""); + remhost = strvcat(inet_ntoa(addr), at, NULL); + XFREE(cp); } if (remhost == NULL) { plog(XLOG_USER, "lustre: empty host"); diff --git a/include/am_utils.h b/include/am_utils.h index 90d30b3d..d8bcd2f5 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -282,6 +282,7 @@ extern char *get_version_string(void); extern char *inet_dquad(char *, size_t, u_long); extern char *print_wires(void); extern char *str3cat(char *, char *, char *, char *); +extern char *strvcat(const char *, ...); extern char *strealloc(char *, char *); extern char *strip_selectors(char *, char *); extern char *strnsave(const char *, int); diff --git a/libamu/strutil.c b/libamu/strutil.c index 3a480c52..8c321def 100644 --- a/libamu/strutil.c +++ b/libamu/strutil.c @@ -268,3 +268,37 @@ xvsnprintf(char *str, size_t size, const char *format, va_list ap) return ret; } + +static size_t +vstrlen(const char *src, va_list ap) +{ + size_t len = strlen(src); + while ((src = va_arg(ap, const char *)) != NULL) + len += strlen(src); + return len; +} + +static void +vstrcpy(char *dst, const char *src, va_list ap) +{ + strcpy(dst, src); + while ((src = va_arg(ap, const char *)) != NULL) + strcat(dst, src); +} + +char * +strvcat(const char *src, ...) +{ + size_t len; + char *dst; + va_list ap; + + va_start(ap, src); + len = vstrlen(src, ap); + va_end(ap); + dst = xmalloc(len + 1); + va_start(ap, src); + vstrcpy(dst, src, ap); + va_end(ap); + return dst; +} -- 2.43.0