if (!mdns_name) {
char groupname[64], *localhost, *tmp;
/* Extract the host part of the potentially FQDN */
- localhost = virGetHostname();
- if (localhost == NULL) {
- virReportOOMError(NULL);
+ localhost = virGetHostname(NULL);
+ if (localhost == NULL)
goto cleanup;
- }
+
if ((tmp = strchr(localhost, '.')))
*tmp = '\0';
snprintf(groupname, sizeof(groupname)-1, "Virtualization Host %s", localhost);
return ret;
}
-static char *lxcGetHostname (virConnectPtr conn)
-{
- char *result;
-
- result = virGetHostname();
- if (result == NULL) {
- virReportSystemError (conn, errno,
- "%s", _("failed to determine host name"));
- return NULL;
- }
- /* Caller frees this string. */
- return result;
-}
-
static int lxcFreezeContainer(lxc_driver_t *driver, virDomainObjPtr vm)
{
int timeout = 1000; /* In milliseconds */
NULL, /* supports_feature */
NULL, /* type */
lxcVersion, /* version */
- lxcGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
NULL, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */
lxcGetCapabilities, /* getCapabilities */
return ret;
}
-static char *
-qemudGetHostname (virConnectPtr conn)
-{
- char *result;
-
- result = virGetHostname();
- if (result == NULL) {
- virReportSystemError (conn, errno,
- "%s", _("failed to determine host name"));
- return NULL;
- }
- /* Caller frees this string. */
- return result;
-}
-
static int qemudListDomains(virConnectPtr conn, int *ids, int nids) {
struct qemud_driver *driver = conn->privateData;
int n;
if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
/* Get hostname */
- if ((hostname = virGetHostname()) == NULL) {
- virReportSystemError (dconn, errno,
- "%s", _("failed to determine host name"));
+ if ((hostname = virGetHostname(dconn)) == NULL)
goto cleanup;
- }
/* XXX this really should have been a properly well-formed
* URI, but we can't add in tcp:// now without breaking
qemudSupportsFeature, /* supports_feature */
qemudGetType, /* type */
qemudGetVersion, /* version */
- qemudGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
qemudGetMaxVCPUs, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */
qemudGetCapabilities, /* getCapabilities */
return (0);
}
-static char *testGetHostname (virConnectPtr conn)
-{
- char *result;
-
- result = virGetHostname();
- if (result == NULL) {
- virReportSystemError(conn, errno,
- "%s", _("cannot lookup hostname"));
- return NULL;
- }
- /* Caller frees this string. */
- return result;
-}
-
static int testGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
const char *type ATTRIBUTE_UNUSED)
{
NULL, /* supports_feature */
NULL, /* type */
testGetVersion, /* version */
- testGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
testGetMaxVCPUs, /* getMaxVcpus */
testNodeGetInfo, /* nodeGetInfo */
testGetCapabilities, /* getCapabilities */
return ret;
}
-static char *
-umlGetHostname (virConnectPtr conn)
-{
- char *result;
-
- result = virGetHostname();
- if (result == NULL) {
- virReportSystemError(conn, errno,
- "%s", _("cannot lookup hostname"));
- return NULL;
- }
- /* Caller frees this string. */
- return result;
-}
-
static int umlListDomains(virConnectPtr conn, int *ids, int nids) {
struct uml_driver *driver = conn->privateData;
int n;
NULL, /* supports_feature */
umlGetType, /* type */
umlGetVersion, /* version */
- umlGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
NULL, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */
umlGetCapabilities, /* getCapabilities */
#define AI_CANONIDN 0
#endif
-char *virGetHostname(void)
+char *virGetHostname(virConnectPtr conn)
{
int r;
char hostname[HOST_NAME_MAX+1], *result;
struct addrinfo hints, *info;
r = gethostname (hostname, sizeof(hostname));
- if (r == -1)
+ if (r == -1) {
+ virReportSystemError (conn, errno,
+ "%s", _("failed to determine host name"));
return NULL;
+ }
NUL_TERMINATE(hostname);
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME|AI_CANONIDN;
hints.ai_family = AF_UNSPEC;
r = getaddrinfo(hostname, NULL, &hints, &info);
- if (r != 0)
+ if (r != 0) {
+ ReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("getaddrinfo failed for '%s': %s"),
+ hostname, gai_strerror(r));
return NULL;
+ }
if (info->ai_canonname == NULL) {
+ ReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("could not determine canonical host name"));
freeaddrinfo(info);
return NULL;
}
/* Caller frees this string. */
result = strdup (info->ai_canonname);
+ if (!result)
+ virReportOOMError(conn);
+
freeaddrinfo(info);
return result;
}
static inline int getgid (void) { return 0; }
#endif
-char *virGetHostname(void);
+char *virGetHostname(virConnectPtr conn);
int virKillProcess(pid_t pid, int sig);
return 0;
}
-static char *vboxGetHostname(virConnectPtr conn) {
- char *hostname;
-
- /* the return string should be freed by caller */
- hostname = virGetHostname();
- if (hostname == NULL) {
- vboxError(conn, VIR_ERR_INTERNAL_ERROR,"%s",
- "failed to determine host name");
- return NULL;
- }
-
- return hostname;
-}
-
static int vboxGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) {
vboxGlobalData *data = conn->privateData;
PRUint32 maxCPUCount = 0;
NULL, /* supports_feature */
NULL, /* type */
vboxGetVersion, /* version */
- vboxGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
vboxGetMaxVcpus, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */
vboxGetCapabilities, /* getCapabilities */
return -1;
}
-/* NB: Even if connected to the proxy, we're still on the
- * same machine.
- */
-static char *
-xenUnifiedGetHostname (virConnectPtr conn)
-{
- char *result;
-
- result = virGetHostname();
- if (result == NULL) {
- virReportSystemError(conn, errno,
- "%s", _("cannot lookup hostname"));
- return NULL;
- }
- /* Caller frees this string. */
- return result;
-}
-
static int
xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
{
xenUnifiedSupportsFeature, /* supports_feature */
xenUnifiedType, /* type */
xenUnifiedGetVersion, /* version */
- xenUnifiedGetHostname, /* getHostname */
+ virGetHostname, /* getHostname */
xenUnifiedGetMaxVcpus, /* getMaxVcpus */
xenUnifiedNodeGetInfo, /* nodeGetInfo */
xenUnifiedGetCapabilities, /* getCapabilities */
* deallocates this string.
*/
if (uri_in == NULL) {
- *uri_out = virGetHostname();
- if (*uri_out == NULL) {
- virReportOOMError(dconn);
+ *uri_out = virGetHostname(dconn);
+ if (*uri_out == NULL)
return -1;
- }
}
return 0;
char *thatHost = NULL;
char *thisHost = NULL;
- if (!(thisHost = virGetHostname())) {
+ if (!(thisHost = virGetHostname(ctl->conn))) {
vshError(ctl, "%s", _("Failed to get local hostname"));
goto cleanup;
}