diff options
author | Aravinda VK <avishwan@redhat.com> | 2016-10-25 12:56:05 +0530 |
---|---|---|
committer | Aravinda VK <avishwan@redhat.com> | 2016-11-30 21:55:47 -0800 |
commit | 7b1ca6061f6e4187e1457e7f32de0e8f2adcc854 (patch) | |
tree | a2330dbf61e9e27450b6e3033a8b3f8f38260435 | |
parent | 285987ab9ed968a37df1bada56f137579146a23f (diff) |
geo-rep/cli: Validate Checkpoint label
Checkpoint command accepts "now" or any other Time
in "%Y-%m-%d %H:%M:%S" format as label.
Validation added with this patch for the input label. Checkpoint set
will fail for invalid label.
> Reviewed-on: http://review.gluster.org/15721
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
> Reviewed-by: Kotresh HR <khiremat@redhat.com>
BUG: 1395628
Change-Id: I23518c151ab4b294f64cae3b78baaacb3d8f7b82
Signed-off-by: Aravinda VK <avishwan@redhat.com>
(cherry picked from commit 8a1993b32f476765f9f5c9294e7c3f2ae75198a0)
Reviewed-on: http://review.gluster.org/15856
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Kotresh HR <khiremat@redhat.com>
Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
-rw-r--r-- | cli/src/cli-cmd-parser.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index f1a60117d84..cc9dec95f60 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -13,6 +13,7 @@ #include <stdint.h> #include <pthread.h> #include <fnmatch.h> +#include <time.h> #ifndef _CONFIG_H #define _CONFIG_H @@ -2357,6 +2358,9 @@ config_parse (const char **words, int wordcount, dict_t *dict, char *append_str = NULL; size_t append_len = 0; char *subop = NULL; + char *ret_chkpt = NULL; + struct tm checkpoint_time; + char chkpt_buf[20] = ""; switch ((wordcount - 1) - cmdi) { case 0: @@ -2418,6 +2422,27 @@ config_parse (const char **words, int wordcount, dict_t *dict, } snprintf (append_str, 300, "%" GF_PRI_SECOND, tv.tv_sec); + } else if ((strcmp (words[cmdi + 1], "checkpoint") == 0) && + (strcmp (append_str, "now") != 0)) { + memset(&checkpoint_time, 0, sizeof(struct tm)); + ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S", + &checkpoint_time); + + if (ret_chkpt == NULL) { + ret = -1; + cli_err ("Invalid Checkpoint label. Use format " + "\"Y-m-d H:M:S\", Example: 2016-10-25 15:30:45"); + goto out; + } + GF_FREE (append_str); + append_str = GF_CALLOC (1, 300, cli_mt_append_str); + if (!append_str) { + ret = -1; + goto out; + } + strftime (chkpt_buf, sizeof(chkpt_buf), "%s", + &checkpoint_time); + snprintf (append_str, 300, "%s", chkpt_buf); } ret = dict_set_dynstr (dict, "op_value", append_str); |