diff options
Diffstat (limited to 'cli/src/input.c')
| -rw-r--r-- | cli/src/input.c | 62 |
1 files changed, 21 insertions, 41 deletions
diff --git a/cli/src/input.c b/cli/src/input.c index 2c67b354d..a8ea46c6d 100644 --- a/cli/src/input.c +++ b/cli/src/input.c @@ -1,22 +1,12 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2010-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -41,13 +31,10 @@ cli_batch (void *d) state = d; - if (state->mode == GLUSTER_MODE_SCRIPT) - ret = cli_cmd_process (state, state->argc - 2, state->argv + 2); - else - ret = cli_cmd_process (state, state->argc, state->argv); + ret = cli_cmd_process (state, state->argc, state->argv); - gf_log ("", GF_LOG_NORMAL, "Exiting with: %d", ret); - exit (ret); + gf_log ("", GF_LOG_INFO, "Exiting with: %d", ret); + exit (-ret); return NULL; } @@ -74,9 +61,11 @@ cli_input (void *d) if (len > 0 && cmd[len - 1] == '\n') //strip trailing \n cmd[len - 1] = '\0'; ret = cli_cmd_process_line (state, cmd); + if (ret != 0 && state->mode & GLUSTER_MODE_ERR_FATAL) + break; } - exit (ret); + exit (-ret); return NULL; } @@ -86,29 +75,20 @@ int cli_input_init (struct cli_state *state) { int ret = 0; - gf_boolean_t is_batch = _gf_false; - - if (1 < state->argc) { - if (!strcmp ("mode", state->argv[0]) && - !strcmp ("script", state->argv[1])) { - state->mode = GLUSTER_MODE_SCRIPT; - if (2 < state->argc) - is_batch = _gf_true; - } else { - is_batch = _gf_true; - } - } else if (1 == state->argc) { - is_batch = _gf_true; - } - if (is_batch) { + if (state->argc) { ret = pthread_create (&state->input, NULL, cli_batch, state); return ret; } - state->prompt = "gluster> "; + if (isatty (STDIN_FILENO)) { + state->prompt = "gluster> "; - cli_rl_enable (state); + cli_rl_enable (state); + } else { + state->prompt = ""; + state->mode = GLUSTER_MODE_SCRIPT | GLUSTER_MODE_ERR_FATAL; + } if (!state->rl_enabled) ret = pthread_create (&state->input, NULL, cli_input, state); |
