Chromium Code Reviews| Index: lib/cros_vm_lib.sh |
| diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh |
| index d28539c14d5b068fc3003a6be971c8bf64d29c5c..bc4379a47cd5dea911d35ff56054797316eb3c79 100644 |
| --- a/lib/cros_vm_lib.sh |
| +++ b/lib/cros_vm_lib.sh |
| @@ -19,6 +19,22 @@ function get_pid() { |
| sudo cat "${KVM_PID_FILE}" |
| } |
| +# General purpose wait for process to terminate. |
| +# Incrementally backs off timeouts until it is waiting for 30 seconds and then |
|
petkov
2010/12/09 23:01:28
by 30 you mean 31 -- 1+2+4+8+16? with the exponent
|
| +# tries to kill -9 before returning. |
| +# $1 the process id. |
| +function wait_on_pid() { |
| + local timeout=1 |
| + while ps -p ${1} > /dev/null && [ ${timeout} -le 30 ]; do |
| + warn "Process still running, sleeping for ${timeout}" |
| + sleep ${timeout} |
| + timeout=$((timeout*2)) |
| + done |
| + if ps -p ${1}; then |
| + sudo kill -9 ${1} |
|
petkov
2010/12/09 23:01:28
the bonus kill here seems to contradict with the f
|
| + fi |
| +} |
| + |
| # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work |
| # on Hardy. |
| # $1: Path to the virtual image to start. |
| @@ -99,6 +115,7 @@ function stop_kvm() { |
| if [ -n "${pid}" ]; then |
| echo "Killing ${pid}" >&2 |
| sudo kill ${pid} |
| + wait_on_pid ${pid} |
| sudo rm "${KVM_PID_FILE}" |
| else |
| echo "No kvm pid found to stop." >&2 |