diff options
author | Kaushal M <kaushal@redhat.com> | 2012-04-19 13:17:49 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2012-04-20 09:32:17 -0700 |
commit | e2216fbc37831f76039cae77bf724550827daa0f (patch) | |
tree | 86621048b0f18383ed16a75fa64174663c623d1f /libglusterfs/src/common-utils.c | |
parent | 3a26a7324128aed8181959b995d09ffc19ec2265 (diff) |
cli: Strip whitespace from "volume set" option values
Strips the whitespace from options values before sending to glusterd.
This prevents options containing whitespace to be written to the volfiles which
would cause the volfile parser to fail.
Change-Id: I46faee7b0853141fa102d06bb067c7ab499a2f6e
BUG: 813937
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.com/3192
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r-- | libglusterfs/src/common-utils.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index cc73a8b7abb..0e133c005e3 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -2024,3 +2024,34 @@ gf_client_pid_check (gf_client_pid_t npid) return ( (npid > GF_CLIENT_PID_MIN) && (npid < GF_CLIENT_PID_MAX) ) ? 0 : -1; } + +/* Strips all whitespace characters in a string and returns length of new string + * on success + */ +int +gf_strip_whitespace (char *str, int len) +{ + int i = 0; + int new_len = 0; + char *new_str = NULL; + + GF_ASSERT (str); + + new_str = GF_CALLOC (1, len + 1, gf_common_mt_char); + if (new_str == NULL) + return -1; + + for (i = 0; i < len; i++) { + if (!isspace (str[i])) + new_str[new_len++] = str[i]; + } + new_str[new_len] = '\0'; + + if (new_len != len) { + memset (str, 0, len); + strncpy (str, new_str, new_len); + } + + GF_FREE (new_str); + return new_len; +} |