Add options to make writing a front end easier
cover Add options to make writing a front end easier
Howdy,
I've been working on a QEMU front end for a bit now. The following patch introduces a number of things to make writing front ends in general a bit easier. This includes making the char devices exposable as unix sockets and adding a daemonize option.
Unix sockets are useful for a front end because their permissions can be controlled and it's easier to guarantee uniqueness (verses trying to find an unused TCP port).
The daemonize option is useful as it provides a deterministic way to know that QEMU is ready to accept connections (for something like VNC). Otherwise, you have to use a connect loop and timeout attempting to connect. This gets particularly ugly when an error occurs for some reason.
I've made an attempt to support the Win32 build but I haven't verified that current CVS is buildable (my changes shouldn't make it any worse).
Regards,
Anthony Liguori
PATCH 1/3 Add unix domain socket character device
This patch introduces a unix: domain socket. It reuses the tcp: code so it will behave almost identically.
An example usage would be:
qemu -hda ~/win2k.img -monitor unix:/home/anthony/monitor.sock,server,nowait
Regards,
Anthony Liguori
qemu_socket.h +1 -0
@@ -19,6 +19,7 @@#include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> +#include <sys/un.h> #define socket_error () errno#define closesocket (s) close(s)
vl.c +97 -20
213 lines not on this page · raw message
qemu-doc.texi +5 -0
@@ -586,6 +586,11 @@ sequence. Typically in unix telnet you sequence. Typically in unix telnet you do it with Control-] and then type "send break" followed by pressing the enter key. +@item unix:path[,server][,nowait] +A unix domain socket is used instead of a tcp socket. The option works the +same as if you had specified @code{-serial tcp} except the unix domain socket +@var{path} is used for connections. + @end table @item -parallel dev
PATCH 2/3 Add unix domain socket and interface restriction to VNC
In reply to Anthony LiguoriThe following patch allows a user to restrict which interface the VNC server will listen on. It also adds unix domain socket support to VNC.
N.B. The old syntax of:
qemu -vnc 1
Is now:
qemu -vnc :1
Also, the syntax between the unix char devices and VNC is a bit different. This is because the current VNC server does not support reverse connections. I don't really think supporting reverse connections is all that useful so I'm happy to leave it this way.
Some example usages:
qemu -hda ~/win2k.img -vnc :1 # listen on 0.0.0.0:5901 TCP
qemu -hda ~/win2k.img -vnc 192.168.1.0:1 # listen on 192.168.1.0:5901 TCP
qemu -hda ~/win2k.img -vnc unix:/home/anthony/vga.sock # listen on unix socket /home/anthony/vga.sock
Regards,
Anthony Liguori
qemu-doc.texi +10 -3
@@ -247,14 +247,21 @@ the console. Therefore, you can still us the console. Therefore, you can still use QEMU to debug a Linux kernel with a serial console. -@item -vnc d +@item -vnc display Normally, QEMU uses SDL to display the VGA output. With this option, -you can have QEMU listen on VNC display @var{d} and redirect the VGA +you can have QEMU listen on VNC display @var{display} and redirect the VGA display over the VNC session. It is very useful to enable the usb tablet device when using this option (option @option{-usbdevice tablet}). When using the VNC display, you must use the @option{-k} -option to set the keyboard layout. +option to set the keyboard layout if you are not using en-us. + +@var{display} may be in the form @var{interface:d}, in which case connections +will only be allowed from @var{interface} on display @var{d}. Optionally, +@var{interface} can be omitted. @var{display} can also be in the form +@var{unix:path} where @var{path} is the location of a unix socket to listen for +connections on. + @item -k language
vl.c +3 -7
@@ -152,7 +152,7 @@ int usb_enabled = 0;int usb_enabled =0 ;static VLANState *first_vlan;int smp_cpus =1 ; -int vnc_display =-1 ; +const char *vnc_display;#if defined(TARGET_SPARC )#define MAX_CPUS 16#elif defined(TARGET_I386 )
@@ -6818,11 +6818,7 @@ int main(int argc, char **argv) }break ;case QEMU_OPTION_vnc: - vnc_display =atoi (optarg); -if (vnc_display <0 ) { -fprintf (stderr,"Invalid VNC display\n" ); -exit (1 ); - } + vnc_display = optarg;break ;case QEMU_OPTION_no_acpi: acpi_enabled =0 ;
@@ -6946,7 +6942,7 @@ int main(int argc, char **argv)/* terminal init */ if (nographic) {dumb_display_init (ds); - }else if (vnc_display !=-1 ) { + }else if (vnc_display !=NULL ) {vnc_display_init (ds, vnc_display); }else {#if defined(CONFIG_SDL )
vl.h +1 -1
@@ -867,7 +867,7 @@ void cocoa_display_init(DisplayState *dsvoid cocoa_display_init (DisplayState *ds,int full_screen);/* vnc.c */ -void vnc_display_init (DisplayState *ds,int display); +void vnc_display_init (DisplayState *ds,const char *display);/* ide.c */ #define MAX_DISKS 4
vnc.c +71 -37
124 lines not on this page · raw message
PATCH 3/3 Add daemonize option
In reply to Anthony LiguoriThis adds a -daemonize option. This option is mostly useful for front-ends as it provides a deterministic way to connect to QEMU's various devices. For instance, if you wanted to execute:
qemu -hda ~/win2k.img -monitor telnet:localhost:1024,server & telnet localhost:1024
Occasionally, you will get a connection refused as there is a race condition. However, with this option, you can write:
qemu -hda ~/win2k.img -monitor telnet:localhost:1024,server -daemonize telnet localhost:1024
And it should always work. This is because the daemonize code doesn't detach until after all of the character devices are initialized.
Regards,
Anthony Liguori
qemu-doc.texi +6 -0
@@ -308,6 +308,12 @@ Start in full screen. @item -pidfile file Store the QEMU process PID in @var{file}. It is useful if you launch QEMU from a script. + +@item -daemonize +Daemonize the QEMU process after initialization. QEMU will not detach from +standard IO until it is ready to receive connections on any of its devices. +This option is a useful way for external programs to launch QEMU without having +to cope with initialization race conditions. @item -win2k-hack Use it when installing Windows 2000 to avoid a disk full bug. After
vl.c +81 -0
126 lines not on this page · raw message
PATCH 3/3 Add daemonize option
Review int main(int argc, char **argv) · line 6839
Quoted 8 lines · Anthony Liguori
(quoted diff) +2
-0@@ -6826,9 +6833,59 @@ int main(int argc, char **argv) case QEMU_OPTION_no_reboot: no_reboot = 1; break; + case QEMU_OPTION_daemonize: + daemonize = 1; }
The indenting is off here and it's missing a break. New patch attached. Sorry 'bout that.
BTW, all of these patches are available in my QEMU patch queue (including a few that I haven't yet submitted here).
http://hg.codemonkey.ws/qemu-pq
Regards,
Anthony Liguori
qemu-doc.texi +6 -0
@@ -308,6 +308,12 @@ Start in full screen. @item -pidfile file Store the QEMU process PID in @var{file}. It is useful if you launch QEMU from a script. + +@item -daemonize +Daemonize the QEMU process after initialization. QEMU will not detach from +standard IO until it is ready to receive connections on any of its devices. +This option is a useful way for external programs to launch QEMU without having +to cope with initialization race conditions. @item -win2k-hack Use it when installing Windows 2000 to avoid a disk full bug. After
vl.c +82 -0
127 lines not on this page · raw message