Change the pid logic to reuse a file if the pid no longer exists.

BUG=chromium-os:21610
TEST=Ran cros_start_vm/cros_stop_vm ... start_vm with same pid after manually
closing it, etc.

Change-Id: If4062c452a135d39a280374cbbebfa852e744022
Reviewed-on: http://gerrit.chromium.org/gerrit/9974
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
This commit is contained in:
Chris Sosa 2011-10-20 15:20:02 -07:00 committed by Gerrit
parent 67145df2a4
commit 9d9a1b1017

View File

@ -48,19 +48,22 @@ function kvm_version_greater_equal() {
# $1: Path to the virtual image to start. # $1: Path to the virtual image to start.
function start_kvm() { function start_kvm() {
# Override default pid file. # Override default pid file.
local start_vm=0
[ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid}
if [ -e "${KVM_PID_FILE}" ]; then if [ -f "${KVM_PID_FILE}" ]; then
local pid=$(get_pid) local pid=$(get_pid)
# Check if the process exists. # Check if the process exists.
if ps -p ${pid} > /dev/null ; then if ps -p ${pid} > /dev/null ; then
echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2
start_vm=1
else else
# Let's be safe in case they specified a file that isn't a pid file. # Let's be safe in case they specified a file that isn't a pid file.
echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2 echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2
exit 1
fi fi
else fi
# No pid specified by PID file. Let's create a VM instance in this case.
# No kvm specified by pid file found, start a new one.
if [ ${start_vm} -eq 0 ]; then
echo "Starting a KVM instance" >&2 echo "Starting a KVM instance" >&2
local nographics="" local nographics=""
local usesnapshot="" local usesnapshot=""