aboutsummaryrefslogtreecommitdiff
path: root/kvmx
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-07-10 13:37:27 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-07-10 13:37:27 -0300
commit467ab3fd675641e7f1ae470a951aeaafeee7fc35 (patch)
tree34652bcc48943ecdad16097833c82a0bb3e7c9bb /kvmx
parent7f8c98b1bfaf205f538b7de0104fd7125832348b (diff)
downloadkvmx-467ab3fd675641e7f1ae470a951aeaafeee7fc35.tar.gz
kvmx-467ab3fd675641e7f1ae470a951aeaafeee7fc35.tar.bz2
Adds pid action
Diffstat (limited to 'kvmx')
-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
}