]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Make avahi startup more robust.
authorChris Lalancette <clalance@redhat.com>
Tue, 23 Mar 2010 13:01:37 +0000 (09:01 -0400)
committerChris Lalancette <clalance@redhat.com>
Wed, 21 Apr 2010 20:16:36 +0000 (16:16 -0400)
If the hostname of the current virtualization machine
could not be resolved, then libvirtd would fail to
start.  However, for disconnected operation (on a laptop,
for instance) the hostname may very legitimately not
be resolvable.  This patch makes it so that if we can't
resolve the hostname, avahi doesn't fail, it just uses
a less useful MDNS string.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
daemon/libvirtd.c

index 863bf21f3b29257c30810fa119ba4d234a551d98..4533f4071c983faefba21a3ef8e8ad204aa131f1 100644 (file)
@@ -998,22 +998,34 @@ static int qemudNetworkInit(struct qemud_server *server) {
         struct libvirtd_mdns_group *group;
         struct qemud_socket *sock;
         int port = 0;
+        int ret;
 
         server->mdns = libvirtd_mdns_new();
 
         if (!mdns_name) {
-            char groupname[64], *localhost, *tmp;
-            /* Extract the host part of the potentially FQDN */
+            char *groupname, *localhost, *tmp;
+
             localhost = virGetHostname(NULL);
             if (localhost == NULL)
+                /* we couldn't resolve the hostname; assume that we are
+                 * running in disconnected operation, and report a less
+                 * useful Avahi string
+                 */
+                ret = virAsprintf(&groupname, "Virtualization Host");
+            else {
+                /* Extract the host part of the potentially FQDN */
+                if ((tmp = strchr(localhost, '.')))
+                    *tmp = '\0';
+                ret = virAsprintf(&groupname, "Virtualization Host %s",
+                                  localhost);
+            }
+            VIR_FREE(localhost);
+            if (ret < 0) {
+                virReportOOMError();
                 goto cleanup;
-
-            if ((tmp = strchr(localhost, '.')))
-                *tmp = '\0';
-            snprintf(groupname, sizeof(groupname)-1, "Virtualization Host %s", localhost);
-            groupname[sizeof(groupname)-1] = '\0';
+            }
             group = libvirtd_mdns_add_group(server->mdns, groupname);
-            VIR_FREE(localhost);
+            VIR_FREE(groupname);
         } else {
             group = libvirtd_mdns_add_group(server->mdns, mdns_name);
         }