+Wed Jan 7 11:38:04 CET 2009 Daniel Veillard <veillard@redhat.com>
+
+ * src/libvirt_private.syms src/qemu_driver.c src/test.c
+ src/uml_driver.c src/util.c src/util.h src/xen_unified.c:
+ unify hostname lookup using virGetHostname convenience function,
+ patch by David Lutterkort
+
Tue Jan 6 20:38:23 +0100 2009 Jim Meyering <meyering@redhat.com>
update from gnulib; use its time_r module for localtime_r on mingw
virEventRemoveHandle;
virExec;
virFormatMacAddr;
+virGetHostname;
virParseMacAddr;
virFileDeletePid;
virFileExists;
static char *
qemudGetHostname (virConnectPtr conn)
{
- int r;
- char hostname[HOST_NAME_MAX+1], *str;
+ char *result;
- r = gethostname (hostname, HOST_NAME_MAX+1);
- if (r == -1) {
+ result = virGetHostname();
+ if (result == NULL) {
qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
"%s", strerror (errno));
return NULL;
}
/* Caller frees this string. */
- str = strdup (hostname);
- if (str == NULL) {
- qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
- return NULL;
- }
- return str;
+ return result;
}
static int qemudListDomains(virConnectPtr conn, int *ids, int nids) {
virRegisterStateDriver(&qemuStateDriver);
return 0;
}
-
static char *testGetHostname (virConnectPtr conn)
{
- int r;
- char hostname [HOST_NAME_MAX+1], *str;
+ char *result;
- r = gethostname (hostname, HOST_NAME_MAX+1);
- if (r == -1) {
+ result = virGetHostname();
+ if (result == NULL) {
testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
- str = strdup (hostname);
- if (str == NULL) {
- testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
- strerror (errno));
- return NULL;
- }
- return str;
+ /* Caller frees this string. */
+ return result;
}
static int testGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED,
static char *
umlGetHostname (virConnectPtr conn)
{
- int r;
- char hostname[HOST_NAME_MAX+1], *str;
+ char *result;
- r = gethostname (hostname, HOST_NAME_MAX+1);
- if (r == -1) {
+ result = virGetHostname();
+ if (result == NULL) {
umlReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
"%s", strerror (errno));
return NULL;
}
/* Caller frees this string. */
- str = strdup (hostname);
- if (str == NULL) {
- umlReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
- "%s", strerror (errno));
- return NULL;
- }
- return str;
+ return result;
}
static int umlListDomains(virConnectPtr conn, int *ids, int nids) {
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
+#include <netdb.h>
#include "virterror_internal.h"
#include "logging.h"
return idx;
}
+#ifndef AI_CANONIDN
+#define AI_CANONIDN 0
+#endif
+
+char *virGetHostname(void)
+{
+ int r;
+ char hostname[HOST_NAME_MAX+1], *result;
+ struct addrinfo hints, *info;
+
+ r = gethostname (hostname, sizeof(hostname));
+ if (r == -1)
+ 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)
+ return NULL;
+ if (info->ai_canonname == NULL) {
+ freeaddrinfo(info);
+ return NULL;
+ }
+
+ /* Caller frees this string. */
+ result = strdup (info->ai_canonname);
+ freeaddrinfo(info);
+ return result;
+}
+
/* send signal to a single process */
int virKillProcess(pid_t pid, int sig)
{
static inline int getgid (void) { return 0; }
#endif
+char *virGetHostname(void);
+
int virKillProcess(pid_t pid, int sig);
#endif /* __VIR_UTIL_H__ */
static char *
xenUnifiedGetHostname (virConnectPtr conn)
{
- int r;
- char hostname [HOST_NAME_MAX+1], *str;
+ char *result;
- r = gethostname (hostname, HOST_NAME_MAX+1);
- if (r == -1) {
- xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
- return NULL;
- }
- str = strdup (hostname);
- if (str == NULL) {
+ result = virGetHostname();
+ if (result == NULL) {
xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
return NULL;
}
- return str;
+ /* Caller frees this string. */
+ return result;
}
static int