diff options
author | Csaba Henk <csaba@gluster.com> | 2011-04-21 16:43:48 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-04-22 04:05:20 -0700 |
commit | de809504282731332c9bc0fc7f7da5be34f206ce (patch) | |
tree | 4df4a6af2d6a21f315ead5c4904d0002ec559e43 /cli/src | |
parent | 5e59de561e49e8f401cf0786635c05c31cc3dfb8 (diff) |
cli: adhere to timeouts properly
Signed-off-by: Csaba Henk <csaba@gluster.com>
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/src')
-rw-r--r-- | cli/src/cli-cmd.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index 3cd6efb81d7..cb0199b0664 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); |