]> xenbits.xensource.com Git - libvirt.git/commitdiff
* src/libvirt_private.syms src/qemu_driver.c src/test.c
authorDaniel Veillard <veillard@redhat.com>
Wed, 7 Jan 2009 10:43:16 +0000 (10:43 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 7 Jan 2009 10:43:16 +0000 (10:43 +0000)
  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
daniel

ChangeLog
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

index fdf589451a253fc95c35db282e6868aec9e79d34..36b497588e56e90f00bd6046efccb43e6ce2cee9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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
index f502e12e7e859e589d64dbcbf3e8841b7ff71d16..6b48ea4f391791fbf8902d3459f86690cdc8d85c 100644 (file)
@@ -277,6 +277,7 @@ virEventAddHandle;
 virEventRemoveHandle;
 virExec;
 virFormatMacAddr;
+virGetHostname;
 virParseMacAddr;
 virFileDeletePid;
 virFileExists;
index b38ecd62a7d6167c3490f0f57edccb2a7ae9fa18..7307be5686d8d448bd290c8b521361ca9149678a 100644 (file)
@@ -1636,23 +1636,16 @@ cleanup:
 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) {
@@ -4326,4 +4319,3 @@ int qemuRegister(void) {
     virRegisterStateDriver(&qemuStateDriver);
     return 0;
 }
-
index e91eed91a0c607528a19cee369a4dbe1f444b603..5d28cced6ccdc57936c19e249b8109cbb632f261 100644 (file)
@@ -656,22 +656,16 @@ static int testGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
 
 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,
index 1562042e7ce2a0d4b0a88ca2d502633d83b3e1fd..77e19f6758926007b3fc8a8ea76815e6f858ffa8 100644 (file)
@@ -1149,23 +1149,16 @@ cleanup:
 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) {
index dd18522635c10527177d76677d44a47e8bfc1426..2a9ea6481f038ecef657dc3e2410e8164e016b68 100644 (file)
@@ -47,6 +47,7 @@
 #ifdef HAVE_PATHS_H
 #include <paths.h>
 #endif
+#include <netdb.h>
 
 #include "virterror_internal.h"
 #include "logging.h"
@@ -1338,6 +1339,38 @@ int virDiskNameToIndex(const char *name) {
     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)
 {
index f622bad06c63c9774b47a32f7ea8b95ec495fd28..4fad6df8a1aaefba9a29cface1a0cc13cb64a0d6 100644 (file)
@@ -166,6 +166,8 @@ static inline int getuid (void) { return 0; }
 static inline int getgid (void) { return 0; }
 #endif
 
+char *virGetHostname(void);
+
 int virKillProcess(pid_t pid, int sig);
 
 #endif /* __VIR_UTIL_H__ */
index 4be9b17d059d07e99acc0e37302fa22e705904fb..a4e8d32cee1c4a3bde967ca14fe996e95cee5f46 100644 (file)
@@ -447,20 +447,15 @@ xenUnifiedGetVersion (virConnectPtr conn, unsigned long *hvVer)
 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