OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 # | 4 # |
5 # Common vm functions for use in crosutils. | 5 # Common vm functions for use in crosutils. |
6 | 6 |
7 DEFINE_string kvm_pid "" \ | 7 DEFINE_string kvm_pid "" \ |
8 "Use this pid file. If it exists and is set, use the vm specified by pid." | 8 "Use this pid file. If it exists and is set, use the vm specified by pid." |
9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." | 9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." |
10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." | 10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." |
(...skipping 20 matching lines...) Expand all Loading... |
31 local timeout=1 | 31 local timeout=1 |
32 sudo kill -$2 $1 | 32 sudo kill -$2 $1 |
33 while ps -p $1 > /dev/null && [ ${timeout} -le $3 ]; do | 33 while ps -p $1 > /dev/null && [ ${timeout} -le $3 ]; do |
34 warn "Process still running, sleeping for ${timeout}" | 34 warn "Process still running, sleeping for ${timeout}" |
35 sleep ${timeout} | 35 sleep ${timeout} |
36 timeout=$((timeout*2)) | 36 timeout=$((timeout*2)) |
37 done | 37 done |
38 ! ps -p ${1} > /dev/null | 38 ! ps -p ${1} > /dev/null |
39 } | 39 } |
40 | 40 |
| 41 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work |
| 42 # on Hardy. |
41 # $1: Path to the virtual image to start. | 43 # $1: Path to the virtual image to start. |
42 function start_kvm() { | 44 function start_kvm() { |
43 # Override default pid file. | 45 # Override default pid file. |
44 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} | 46 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} |
45 if [ -e "${KVM_PID_FILE}" ]; then | 47 if [ -e "${KVM_PID_FILE}" ]; then |
46 local pid=$(get_pid) | 48 local pid=$(get_pid) |
47 # Check if the process exists. | 49 # Check if the process exists. |
48 if ps -p ${pid} > /dev/null ; then | 50 if ps -p ${pid} > /dev/null ; then |
49 echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 | 51 echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 |
50 else | 52 else |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if [ -n "${pid}" ]; then | 125 if [ -n "${pid}" ]; then |
124 echo "Killing ${pid}" >&2 | 126 echo "Killing ${pid}" >&2 |
125 blocking_kill ${pid} 1 16 || blocking_kill 9 1 | 127 blocking_kill ${pid} 1 16 || blocking_kill 9 1 |
126 sudo rm "${KVM_PID_FILE}" | 128 sudo rm "${KVM_PID_FILE}" |
127 else | 129 else |
128 echo "No kvm pid found to stop." >&2 | 130 echo "No kvm pid found to stop." >&2 |
129 return 1 | 131 return 1 |
130 fi | 132 fi |
131 fi | 133 fi |
132 } | 134 } |
OLD | NEW |