aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xkvmx48
1 files changed, 42 insertions, 6 deletions
diff --git a/kvmx b/kvmx
index 7911ec4..079ea82 100755
--- a/kvmx
+++ b/kvmx
@@ -745,6 +745,17 @@ EOF
fi
}
+# Get guest PID
+function kvmx_pid {
+ if [ -e "$PIDFILE" ]; then
+ # QEMU might put weird things into pidfile, so we need a simple filter
+ #cat $PIDFILE
+ cut -d ' ' -f 1 $PIDFILE | head -1
+ else
+ return 1
+ fi
+}
+
# Suspend the virtual machine
function kvmx_suspend {
if ! kvmx_running; then
@@ -752,7 +763,12 @@ function kvmx_suspend {
exit 1
fi
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
+
+ if [ -z "$PID" ]; then
+ return 1
+ fi
+
kill -STOP $PID
# Alternative
@@ -777,7 +793,7 @@ function kvmx_running {
return 1
fi
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
if [ -z "$PID" ]; then
return 1
@@ -812,7 +828,12 @@ function kvmx_resume {
exit 1
fi
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
+
+ if [ -z "$PID" ]; then
+ return 1
+ fi
+
kill -CONT $PID
# Alternative
@@ -1254,7 +1275,12 @@ function kvmx_edit {
# Stop a guest
function kvmx_stop {
if kvmx_running; then
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
+
+ if [ -z "$PID" ]; then
+ return 1
+ fi
+
kill $PID
kvmx_xephyr_stop
fi
@@ -1263,7 +1289,12 @@ function kvmx_stop {
# Kill a guest
function kvmx_kill {
if kvmx_running; then
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
+
+ if [ -z "$PID" ]; then
+ return 1
+ fi
+
kill -9 $PID
kvmx_xephyr_stop
fi
@@ -1385,7 +1416,12 @@ function kvmx_status {
return
fi
- PID="`cat $PIDFILE`"
+ PID="`kvmx_pid`"
+
+ if [ -z "$PID" ]; then
+ return 1
+ fi
+
ps $PID
}