Chromium Code Reviews| Index: remote_access.sh |
| diff --git a/remote_access.sh b/remote_access.sh |
| index 794deff8e755ed0a98a35513016e86c3239cdbad..07f7e9adfecb730ef01e993e94f7d160f40c0e92 100644 |
| --- a/remote_access.sh |
| +++ b/remote_access.sh |
| @@ -34,8 +34,37 @@ function remote_sh() { |
| return ${PIPESTATUS[0]} |
| } |
| +# Checks to see if pid $1 is running. |
| +function is_pid_running() { |
| + ps -p ${1} 2>&1 > /dev/null |
| +} |
| + |
| +# Wait function given an additional timeout argument. |
| +# $1 - pid to wait on. |
| +# $2 - timeout to wait for. |
| +function wait_with_timeout() { |
| + local pid=$1 |
| + local timeout=$2 |
| + local timeout_inc=1 |
|
petkov
2011/01/12 22:40:31
maybe
readonly TIMEOUT_INC=1
|
| + local current_timeout=0 |
| + while is_pid_running ${pid} && [ ${current_timeout} -lt ${timeout} ]; do |
| + sleep ${timeout_inc} |
| + current_timeout=$((current_timeout + timeout_inc)) |
| + done |
| + is_pid_running ${pid} |
| +} |
| + |
| +# Robust ping that will monitor ssh and not hang even if ssh hangs. |
| +function ping_ssh() { |
| + remote_sh "true" & |
| + local pid=$! |
| + wait_with_timeout ${pid} 5 |
| + ! kill -9 ${pid} |
| +} |
| + |
| function remote_sh_allow_changed_host_key() { |
| rm -f $TMP_KNOWN_HOSTS |
| + ping_ssh |
| remote_sh "$@" |
| } |