From ebd99e25bf811ab14540f74dd50b445c217e7ee0 Mon Sep 17 00:00:00 2001 From: Kaushik BV Date: Wed, 13 Apr 2011 01:46:09 +0000 Subject: cli: join value arguments of "gsync config-set" with spaces When a given gsync tunable is supposed to hold a command (which can take options), it's quite possible that it spaces in its value. Try to approximate this situation by joining the leftover arguments. Signed-off-by: Kaushik BV Signed-off-by: Csaba Henk Signed-off-by: Anand Avati BUG: 2713 ([glusterfs-3.2.0qa10]: config-set works only for one value) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2713 --- cli/src/cli-cmd-parser.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index a0219a04ad7..ca4c8d315ce 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1122,8 +1122,11 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) { int32_t ret = 0; int32_t config_type = 0; - dict_t *dict = NULL; - gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; + dict_t *dict = NULL; + gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; + char *append_str = NULL; + size_t append_len = 0; + int i = 0; GF_ASSERT (words); GF_ASSERT (options); @@ -1164,11 +1167,34 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) if (strcmp (words [5], "config-set") == 0) { config_type = GF_GSYNC_OPTION_TYPE_CONFIG_SET; + if (wordcount < 8) { + ret = -1; + + goto out; + } + ret = dict_set_str (dict, "op_name", (char *)words[6]); if (ret < 0) goto out; + /*XXX hack to get around the fact, where parsing of + * args is done based on spaces */ + for (i = 7; i < wordcount; i++) + append_len += (strlen (words[i]) + 1); + append_len++; /* trailing strcat will add two bytes, make space for that */ + + append_str = GF_CALLOC (1, append_len, cli_mt_append_str); + if (!append_str) { + ret = -1; + goto out; + } + + for (i = 7; i< wordcount; i++) { + strcat (append_str, words[i]); + strcat (append_str, " "); + } + append_str[append_len - 2] = '\0'; - ret = dict_set_str (dict, "op_value", (char *)words[7]); + ret = dict_set_dynstr (dict, "op_value", append_str); if (ret < 0) goto out; } @@ -1205,9 +1231,12 @@ set_type: *options = dict; out: - if (ret) + if (ret) { if (dict) dict_destroy (dict); + if (append_str) + GF_FREE (append_str); + } return ret; } -- cgit