summaryrefslogtreecommitdiffstats
path: root/cli/src/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/input.c')
-rw-r--r--cli/src/input.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/cli/src/input.c b/cli/src/input.c
index 25a7cb62d..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 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
- General Public License for more details.
-
- You should have received a copy of the GNU 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,10 +31,10 @@ cli_batch (void *d)
state = d;
- cli_cmd_await_connected ();
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;
}
@@ -57,21 +47,25 @@ cli_input (void *d)
int ret = 0;
char cmdbuf[CMDBUFSIZ];
char *cmd = NULL;
+ size_t len = 0;
state = d;
for (;;) {
- cli_out ("%s", state->prompt);
+ printf ("%s", state->prompt);
cmd = fgets (cmdbuf, CMDBUFSIZ, stdin);
if (!cmd)
break;
-
- printf ("processing command: '%s'\n", cmd);
+ len = strlen(cmd);
+ 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;
}
@@ -87,9 +81,14 @@ cli_input_init (struct cli_state *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);