From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FfI4r-0000At-PA for qemu-devel@nongnu.org; Sun, 14 May 2006 11:00:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FfI4q-0000Ah-Ef for qemu-devel@nongnu.org; Sun, 14 May 2006 11:00:12 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FfI4q-0000Ae-7g for qemu-devel@nongnu.org; Sun, 14 May 2006 11:00:12 -0400 Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1FfI72-0001HP-S5 for qemu-devel@nongnu.org; Sun, 14 May 2006 11:02:29 -0400 Message-ID: <446745FA.7090804@gmx.de> Date: Sun, 14 May 2006 17:00:10 +0200 From: Oliver Gerlich MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050601020809000903020208" Subject: [Qemu-devel] [Patch] Publish VNC display with zeroconf Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------050601020809000903020208 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, here's a little gimmick for VNC support :-) The patch makes Qemu publish its VNC display via zeroconf if it is called with -vnc option. The patch uses the avahi-publish helper app for this, which comes with the Avahi suite (eg. in Debian and Ubuntu it's in the avahi-utils package). If avahi-publish is not installed, this patch won't do anything. With the patch applied, you can use the service-discovery-applet under Gnome to see all Qemu instances which use VNC. Under KDE, Krdc offers a list of all zeroconf-published VNC displays (choose "DNS-SD" from the listbox in the upper left corner in Krdc). Regards, Oliver -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQFEZ0X5TFOM6DcNJ6cRApiCAJ0dSa115JeNvXu9PfND5R+E4TqyeQCgvDlK ROoGXIBo2gVLK104J2uKz1M= =8tDu -----END PGP SIGNATURE----- --------------050601020809000903020208 Content-Type: text/plain; name="vnc-avahi-publish.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vnc-avahi-publish.diff" --- qemu-0.8.1/vnc.c 2006-05-03 22:32:58.000000000 +0200 +++ qemu-0.8.1-avahi/vnc.c 2006-05-14 16:21:05.000000000 +0200 @@ -64,6 +64,11 @@ size_t read_handler_expect; }; +#ifndef _WIN32 +#include +pid_t mdns_publish_pid = 0; +#endif + /* TODO 1) Get the queue working for IO. 2) there is some weirdness when using the -S option (the screen is grey @@ -852,6 +857,71 @@ } } +#ifndef _WIN32 +static void vnc_unpublish_mdns(void) +{ + if (mdns_publish_pid != 0) + { + kill(mdns_publish_pid, SIGTERM); + } + return; +} +#endif + +/// Publish VNC display via mdns/zeroconf using the Avahi suite. +/// See RFC 2782 and avahi-publish(1) for more info. +void vnc_publish_mdns(int port) +{ +#ifndef _WIN32 + // Execute avahi helper program in a child process. + pid_t childPid = fork(); + switch(childPid) + { + case -1: + // fork() failed; ignore this. + break; + + case 0: + { + // New child process. + char name[250]; + char portString[10]; + char *argv[10]; + int i = 0; + + sprintf(name, "QEMU instance on port %d", port); + sprintf(portString, "%d", port); + + argv[i++] = "avahi-publish"; // avahi-publish is a helper program from Avahi that publishes DNS-SD records. + argv[i++] = "-s"; // Flag: publish a service. + argv[i++] = name; // Name of the service + argv[i++] = "_rfb._tcp"; // Service type (see http://www.dns-sd.org/ServiceTypes.html) + argv[i++] = portString; // TCP port + argv[i++] = NULL; + + // Close stdout/stderr to suppress output from avahi-publish + close(STDOUT_FILENO); + close(STDERR_FILENO); + + // Execute avahi-publish + execvp(argv[0], argv); + + // This point might be reached, eg. if avahi-publish is not installed. + exit(0); + break; + } + + default: + // Parent process. Record child pid and set exit handler. + mdns_publish_pid = childPid; + atexit(vnc_unpublish_mdns); + break; + } +#endif + + return; +} + void vnc_display_init(DisplayState *ds, int display) { struct sockaddr_in addr; @@ -918,4 +988,6 @@ memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); vnc_dpy_resize(vs->ds, 640, 400); + + vnc_publish_mdns(5900 + display); } --------------050601020809000903020208--