]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Fix: kvmx_disposable: determine guest name using a sequential suffix
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 21 Aug 2020 01:28:49 +0000 (22:28 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 21 Aug 2020 01:28:49 +0000 (22:28 -0300)
kvmx

diff --git a/kvmx b/kvmx
index 8667405d2a62ce4f4d82958ad3fe449734fa4a86..885ebecafed75829d8ff5d798a5346db36ddbebf 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -2185,8 +2185,32 @@ function kvmx_create {
 
 # Disposable guest
 function kvmx_disposable {
-  local date="`date +%Y%m%d%I%M%S`"
-  local disposable="$VM-disposable-$date"
+  # Determine guest name by appending the current date
+  # This approache leads to the following UNIX socket error
+  # if the VM name is too long:
+  #
+  #   UNIX socket path '/var/cache/qemu/.../monitor' is too long
+  #   Path must be less than 108 bytes
+  #
+  #local date="`date +%Y%m%d%I%M%S`"
+  #local disposable="$VM-disposable-$date"
+
+  local disposable="$VM-disposable-"
+  local count=0
+
+  # Determine guest name using a sequential suffix
+  #
+  # This results in smaller guest names which are les prone to
+  # the UNIX socket path issue and also is easier to type
+  while true; do
+    disposable="${disposable}${count}"
+    if ! kvmx list_image ${disposable} &> /dev/null; then
+      break
+    fi
+
+    echo $count
+    let count++
+  done
 
   # Clone and ensure we use a backing file
   kvmx clone $VM $disposable --skell || exit 1