From de809504282731332c9bc0fc7f7da5be34f206ce Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Thu, 21 Apr 2011 16:43:48 +0000 Subject: cli: adhere to timeouts properly 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index 3cd6efb81..cb0199b06 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -267,6 +267,17 @@ cli_cmd_unlock () return 0; } +static void +seconds_from_now (unsigned secs, struct timespec *ts) +{ + struct timeval tv = {0,}; + + gettimeofday (&tv, NULL); + + ts->tv_sec = tv.tv_sec + secs; + ts->tv_nsec = tv.tv_usec * 1000; +} + int cli_cmd_await_response () { @@ -275,8 +286,7 @@ cli_cmd_await_response () cli_op_ret = -1; - time (&ts.tv_sec); - ts.tv_sec += CLI_DEFAULT_CMD_TIMEOUT; + seconds_from_now (CLI_DEFAULT_CMD_TIMEOUT, &ts); while (!cmd_done && !ret) { ret = pthread_cond_timedwait (&cond, &cond_mutex, &ts); @@ -322,8 +332,7 @@ cli_cmd_await_connected (unsigned conn_timo) pthread_mutex_lock (&conn_mutex); { - time (&ts.tv_sec); - ts.tv_sec += conn_timo; + seconds_from_now (conn_timo, &ts); while (!connected && !ret) { ret = pthread_cond_timedwait (&conn, &conn_mutex, &ts); -- cgit