All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Gerlich <olig9@gmx.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [Patch] Publish VNC display with zeroconf
Date: Sun, 14 May 2006 17:00:10 +0200	[thread overview]
Message-ID: <446745FA.7090804@gmx.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

-----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-----

[-- Attachment #2: vnc-avahi-publish.diff --]
[-- Type: text/plain, Size: 2527 bytes --]

--- 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 <signal.h>
+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);
 }

                 reply	other threads:[~2006-05-14 15:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=446745FA.7090804@gmx.de \
    --to=olig9@gmx.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.