From 0a38334bd3b21df2448a869760292c499c59bb0c Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Mon, 18 Apr 2011 17:25:26 +0000 Subject: 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 Signed-off-by: Anand Avati BUG: 2785 (gsyncd logs on slave side go to /dev/null) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2785 --- cli/src/cli-cmd.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index cdcc4be2d7b..3cd6efb81d7 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); -- cgit