[libvirt] [PATCH 1/4] Make avahi startup more robust.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 daemon/libvirtd.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 863bf21..69106ee 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -998,22 +998,29 @@ 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;
+            char *groupname, *localhost, *tmp;
             /* Extract the host part of the potentially FQDN */
             localhost = virGetHostname(NULL);
             if (localhost == NULL)
+                ret = virAsprintf(&groupname, "Virtualization Host");
+            else {
+                if ((tmp = strchr(localhost, '.')))
+                    *tmp = '\0';
+                ret = virAsprintf(&groupname, "Virtualization Host %s",
+                                  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);
         }
-- 
1.6.6.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]