From 25291033269bc22c25450b0c1023c868c1c8c9cc Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Sun, 10 Jun 2018 16:07:54 +0800 Subject: [PATCH] qemu-android: find an available port to listen The script may fail to launch because the port 5555 is bound, e.g., another instance is running. The change tries to find an available port to avoid such an issue. --- rpm/qemu-android | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rpm/qemu-android b/rpm/qemu-android index ac7869b..5e5dc8c 100644 --- a/rpm/qemu-android +++ b/rpm/qemu-android @@ -39,7 +39,7 @@ elif [ -e data.img ]; then fi fi -run_qemu() +run_qemu_on_port() { $QEMU -enable-kvm \ -kernel kernel \ @@ -51,10 +51,19 @@ run_qemu() -boot menu=on \ -drive index=0,if=virtio,id=system,file=$SYSTEMIMG,format=raw,readonly \ -drive index=1,if=virtio,id=ramdisk,file=ramdisk.img,format=raw,readonly \ - -netdev user,id=mynet,hostfwd=tcp::5555-:5555 -device virtio-net-pci,netdev=mynet \ + -netdev user,id=mynet,hostfwd=tcp::$port-:5555 -device virtio-net-pci,netdev=mynet \ $DATA $@ } +run_qemu() +{ + port=5555 + while [ $port -lt 5600 ]; do + run_qemu_on_port $@ && break + let port++ + done +} + # Try to run QEMU in several VGA modes run_qemu -vga virtio -display sdl,gl=on $@ || \ run_qemu -vga qxl -display sdl $@ || \ -- 2.11.0