diff options
author | Mohammed Junaid <junaid@gluster.com> | 2010-10-14 04:14:47 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-10-26 03:01:50 -0700 |
commit | 0d11145c0c2a9bac61398bff2fbab14820f0764a (patch) | |
tree | 32455a29de40be8204316df4ff5af4def11c6558 /cli | |
parent | 2ec661c0729370f0acd966fab0ae644f7e62bd71 (diff) |
takes either 'y' or 'yes' and 'n' or 'no' for stop volume, delete volume and remove-brick
Signed-off-by: Mohammed Junaid <junaid@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1942 (cli: loose parsing of confirmation answer)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1942
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-volume.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 7a15f5cb356..8fb32f5de47 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -317,20 +317,40 @@ out: gf_answer_t cli_cmd_get_confirmation (struct cli_state *state, const char *question) { - char answer = '\0'; + char answer[5] = {'\0', }; char flush = '\0'; + int len = 0; if (state->mode & GLUSTER_MODE_SCRIPT) return GF_ANSWER_YES; - printf ("%s (y/n) ", question); - answer = getchar (); - flush = answer; - while ('\n' != flush) - flush = getchar (); - if ('y' != answer) { - return GF_ANSWER_NO; - } - return GF_ANSWER_YES; + + printf ("%s (y/n) ", question); + + fgets (answer, 4, stdin); + + len = strlen (answer); + + if (answer [len - 1] == '\n'){ + answer [--len] = '\0'; + } else { + do{ + flush = getchar (); + }while (flush != '\n'); + } + + if (len > 3) + goto out; + + if (!strcasecmp (answer, "y") || !strcasecmp (answer, "yes")) + return GF_ANSWER_YES; + + else if (!strcasecmp (answer, "n") || !strcasecmp (answer, "no")) + return GF_ANSWER_NO; + +out: + cli_out ("Invalid input, please enter y/n"); + + return GF_ANSWER_NO; } int |