diff mbox series

[1/2] scripts/runqemu: Allow VNC use as a fallback when there is no DISPLAY set

Message ID 20260310233310.3364647-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/2] scripts/runqemu: Allow VNC use as a fallback when there is no DISPLAY set | expand

Commit Message

Richard Purdie March 10, 2026, 11:33 p.m. UTC
We would like to be able to fall back on QEMU's internal VNC server when
there is no DISPLAY available. Add code to do this, putting a socket for
VNC alongside the network interface tap lock files.

This won't work if tap networking isn't enabled but in most of our use
cases it will be and it avoids having to invent a new location for the
sockets. If there are needs outside this, that can be addressed in future.

Also move the other "publicvnc" code to be alongside the rest of the graphics
parameters for ease of reading the code. The publicvnc option doesn't
work for this use case as it can't handle multiple concurrent qemu istances.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 scripts/runqemu | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/scripts/runqemu b/scripts/runqemu
index 5587d47865c..00ff77a0ed7 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -581,7 +581,6 @@  to your build configuration.
                 self.snapshot = True
             elif arg == 'publicvnc':
                 self.publicvnc = True
-                self.qemu_opt_script += ' -vnc :0'
             elif arg == 'guestagent':
                 self.guest_agent = True
             elif arg == "qmp":
@@ -1468,15 +1467,22 @@  to your build configuration.
         if (self.gl_es == True or self.gl == True) and (self.sdl == False and self.gtk == False):
             raise RunQemuError('Option gl/gl-es needs gtk or sdl option.')
 
+        if self.publicvnc:
+            self.qemu_opt += ' -vnc :0'
+
         # If we have no display option, we autodetect based upon what qemu supports. We
         # need our font setup and show-cusor below so we need to see what qemu --help says
         # is supported so we can pass our correct config in.
         if not self.nographic and not self.sdl and not self.gtk and not self.publicvnc and not self.egl_headless == True:
             output = subprocess.check_output([self.qemu_bin, "--help"], universal_newlines=True, env=self.qemu_environ)
-            if "-display gtk" in output:
+            if "-display gtk" in output and "DISPLAY" in os.environ:
                 self.gtk = True
-            elif "-display sdl" in output:
+            elif "-display sdl" in output and "DISPLAY" in os.environ:
                 self.sdl = True
+            elif "-display vnc" in output and self.taplock_descriptor:
+                vncaddress = "unix:%s" % self.taplock.replace(".lock", ".vnc-socket")
+                logger.info("Using VNC server at %s for graphical output" % vncaddress)
+                self.qemu_opt += " -vnc %s" % vncaddress
             else:
                 self.qemu_opt += ' -display none'