summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-04-18 17:25:26 +0000
committerAnand Avati <avati@gluster.com>2011-04-19 02:30:23 -0700
commit0a38334bd3b21df2448a869760292c499c59bb0c (patch)
treeeab3a72aa391d39e19edc40be79a850fb8cc1c78 /cli
parent184fba37889b87c27af90adf357b38fa95f1e78d (diff)
cli: make it possible to set per-command timeouts for connection
Also make getwd command impatient, having it to time out in 1 sec Signed-off-by: Csaba Henk <csaba@lowlife.hu> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2785 (gsyncd logs on slave side go to /dev/null) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2785
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index cdcc4be..3cd6efb 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -47,16 +47,19 @@ int connected = 0;
int cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
-static gf_boolean_t
+static unsigned
cli_cmd_needs_connection (struct cli_cmd_word *word)
{
if (!strcasecmp ("quit", word->word))
- return _gf_false;
+ return 0;
if (!strcasecmp ("help", word->word))
- return _gf_false;
+ return 0;
- return _gf_true;
+ if (!strcasecmp ("getwd", word->word))
+ return 1;
+
+ return CLI_DEFAULT_CONN_TIMEOUT;
}
int
@@ -98,7 +101,6 @@ cli_cmd_process (struct cli_state *state, int argc, char **argv)
struct cli_cmd_word *word = NULL;
struct cli_cmd_word *next = NULL;
int i = 0;
- gf_boolean_t await_conn = _gf_false;
word = &state->tree.root;
@@ -130,16 +132,12 @@ cli_cmd_process (struct cli_state *state, int argc, char **argv)
if ( strcmp (word->word,"help")==0 )
goto callback;
- await_conn = cli_cmd_needs_connection (word);
-
- if (await_conn) {
- ret = cli_cmd_await_connected ();
- if (ret) {
- cli_out ("Connection failed. Please check if gluster "
- "daemon is operational.");
- gf_log ("", GF_LOG_INFO, "Exiting with: %d", ret);
- exit (ret);
- }
+ ret = cli_cmd_await_connected (cli_cmd_needs_connection (word));
+ if (ret) {
+ cli_out ("Connection failed. Please check if gluster "
+ "daemon is operational.");
+ gf_log ("", GF_LOG_INFO, "Exiting with: %d", ret);
+ exit (ret);
}
callback:
@@ -314,15 +312,18 @@ out:
}
int32_t
-cli_cmd_await_connected ()
+cli_cmd_await_connected (unsigned conn_timo)
{
int32_t ret = 0;
struct timespec ts = {0,};
+ if (!conn_timo)
+ return 0;
+
pthread_mutex_lock (&conn_mutex);
{
time (&ts.tv_sec);
- ts.tv_sec += CLI_DEFAULT_CONN_TIMEOUT;
+ ts.tv_sec += conn_timo;
while (!connected && !ret) {
ret = pthread_cond_timedwait (&conn, &conn_mutex,
&ts);