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. | |
43 # $1: Path to the virtual image to start. | 41 # $1: Path to the virtual image to start. |
44 function start_kvm() { | 42 function start_kvm() { |
45 # Override default pid file. | 43 # Override default pid file. |
46 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} | 44 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} |
47 if [ -e "${KVM_PID_FILE}" ]; then | 45 if [ -e "${KVM_PID_FILE}" ]; then |
48 local pid=$(get_pid) | 46 local pid=$(get_pid) |
49 # Check if the process exists. | 47 # Check if the process exists. |
50 if ps -p ${pid} > /dev/null ; then | 48 if ps -p ${pid} > /dev/null ; then |
51 echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 | 49 echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 |
52 else | 50 else |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if [ -n "${pid}" ]; then | 123 if [ -n "${pid}" ]; then |
126 echo "Killing ${pid}" >&2 | 124 echo "Killing ${pid}" >&2 |
127 blocking_kill ${pid} 1 16 || blocking_kill 9 1 | 125 blocking_kill ${pid} 1 16 || blocking_kill 9 1 |
128 sudo rm "${KVM_PID_FILE}" | 126 sudo rm "${KVM_PID_FILE}" |
129 else | 127 else |
130 echo "No kvm pid found to stop." >&2 | 128 echo "No kvm pid found to stop." >&2 |
131 return 1 | 129 return 1 |
132 fi | 130 fi |
133 fi | 131 fi |
134 } | 132 } |
OLD | NEW |