mirror of https://gitee.com/openkylin/libvirt.git
Make avahi startup more robust.
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>
This commit is contained in:
parent
ce380b8e6f
commit
8274993f29
|
@ -998,22 +998,34 @@ static int qemudNetworkInit(struct qemud_server *server) {
|
||||||
struct libvirtd_mdns_group *group;
|
struct libvirtd_mdns_group *group;
|
||||||
struct qemud_socket *sock;
|
struct qemud_socket *sock;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
server->mdns = libvirtd_mdns_new();
|
server->mdns = libvirtd_mdns_new();
|
||||||
|
|
||||||
if (!mdns_name) {
|
if (!mdns_name) {
|
||||||
char groupname[64], *localhost, *tmp;
|
char *groupname, *localhost, *tmp;
|
||||||
/* Extract the host part of the potentially FQDN */
|
|
||||||
localhost = virGetHostname(NULL);
|
localhost = virGetHostname(NULL);
|
||||||
if (localhost == NULL)
|
if (localhost == NULL)
|
||||||
goto cleanup;
|
/* we couldn't resolve the hostname; assume that we are
|
||||||
|
* running in disconnected operation, and report a less
|
||||||
if ((tmp = strchr(localhost, '.')))
|
* useful Avahi string
|
||||||
*tmp = '\0';
|
*/
|
||||||
snprintf(groupname, sizeof(groupname)-1, "Virtualization Host %s", localhost);
|
ret = virAsprintf(&groupname, "Virtualization Host");
|
||||||
groupname[sizeof(groupname)-1] = '\0';
|
else {
|
||||||
group = libvirtd_mdns_add_group(server->mdns, groupname);
|
/* Extract the host part of the potentially FQDN */
|
||||||
|
if ((tmp = strchr(localhost, '.')))
|
||||||
|
*tmp = '\0';
|
||||||
|
ret = virAsprintf(&groupname, "Virtualization Host %s",
|
||||||
|
localhost);
|
||||||
|
}
|
||||||
VIR_FREE(localhost);
|
VIR_FREE(localhost);
|
||||||
|
if (ret < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
group = libvirtd_mdns_add_group(server->mdns, groupname);
|
||||||
|
VIR_FREE(groupname);
|
||||||
} else {
|
} else {
|
||||||
group = libvirtd_mdns_add_group(server->mdns, mdns_name);
|
group = libvirtd_mdns_add_group(server->mdns, mdns_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue