summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd.c
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-07-26 12:10:08 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-07-27 01:20:12 -0700
commita7795fedd4ee2ed7de2dce89fd782ae20b03f6a4 (patch)
tree60e173fcab4bbcf78060755b93dda83e2b707a42 /cli/src/cli-cmd.c
parentf803fae036177c3b9d9513f5b6300d426366eb62 (diff)
cli: Changes to provide proper exit status for gluster commandline
Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1205 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1205
Diffstat (limited to 'cli/src/cli-cmd.c')
-rw-r--r--cli/src/cli-cmd.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index 4ef8e86cd2a..043cb91d7e4 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -37,6 +37,11 @@
static int cmd_done;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t conn = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t conn_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+int cli_op_ret = 0;
+int connected = 1;
int
cli_cmd_process (struct cli_state *state, int argc, char **argv)
@@ -178,6 +183,7 @@ cli_cmd_await_response ()
pthread_mutex_lock (&cond_mutex);
{
+ cli_op_ret = 0;
while (!cmd_done) {
pthread_cond_wait (&cond, &cond_mutex);
}
@@ -187,15 +193,16 @@ cli_cmd_await_response ()
pthread_mutex_destroy (&cond_mutex);
pthread_cond_destroy (&cond);
- return 0;
+ return cli_op_ret;
}
int
-cli_cmd_broadcast_response ()
+cli_cmd_broadcast_response (int32_t status)
{
pthread_mutex_lock (&cond_mutex);
{
cmd_done = 1;
+ cli_op_ret = status;
pthread_cond_broadcast (&cond);
}
@@ -204,3 +211,37 @@ cli_cmd_broadcast_response ()
return 0;
}
+int32_t
+cli_cmd_await_connected ()
+{
+ pthread_mutex_init (&conn_mutex, NULL);
+ pthread_cond_init (&conn, NULL);
+
+ pthread_mutex_lock (&conn_mutex);
+ {
+ while (!connected) {
+ pthread_cond_wait (&conn, &conn_mutex);
+ }
+ }
+ pthread_mutex_unlock (&conn_mutex);
+
+ pthread_mutex_destroy (&conn_mutex);
+ pthread_cond_destroy (&conn);
+
+ return 0;
+}
+
+int32_t
+cli_cmd_broadcast_connected ()
+{
+ connected = 1;
+ gf_log ("", GF_LOG_NORMAL, "Connected");
+ pthread_mutex_lock (&conn_mutex);
+ {
+ pthread_cond_broadcast (&conn);
+ }
+
+ pthread_mutex_unlock (&conn_mutex);
+
+ return 0;
+}