From b77fcd90f31e7e31a2c2f3f1295f8a8c05f58cbb Mon Sep 17 00:00:00 2001 From: Bob Kuo Date: Wed, 17 Jun 2015 14:31:55 -0500 Subject: [PATCH] Force qemu to use a VNC port by setting vnc_min_port == vnc_max_port Similar to Issue #1288, this prevents a crash when we set the VNC minimum port equivalent to the VNC maximum port --- builder/qemu/step_configure_vnc.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builder/qemu/step_configure_vnc.go b/builder/qemu/step_configure_vnc.go index be452620d..913175dd6 100644 --- a/builder/qemu/step_configure_vnc.go +++ b/builder/qemu/step_configure_vnc.go @@ -32,7 +32,12 @@ func (stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction { var vncPort uint portRange := int(config.VNCPortMax - config.VNCPortMin) for { - vncPort = uint(rand.Intn(portRange)) + config.VNCPortMin + if portRange > 0 { + vncPort = uint(rand.Intn(portRange)) + config.VNCPortMin + } else { + vncPort = config.VNCPortMin + } + log.Printf("Trying port: %d", vncPort) l, err := net.Listen("tcp", fmt.Sprintf(":%d", vncPort)) if err == nil {