* 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
daniel
This commit is contained in:
Daniel Veillard 2009-01-07 10:43:16 +00:00
parent 6c996bfc8f
commit fbba4423e9
8 changed files with 61 additions and 44 deletions

View File

@ -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

View File

@ -277,6 +277,7 @@ virEventAddHandle;
virEventRemoveHandle;
virExec;
virFormatMacAddr;
virGetHostname;
virParseMacAddr;
virFileDeletePid;
virFileExists;

View 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;
}

View 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,

View 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) {

View 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)
{

View 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__ */

View 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) {
result = virGetHostname();
if (result == NULL) {
xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
return NULL;
}
str = strdup (hostname);
if (str == NULL) {
xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
return NULL;
}
return str;
/* Caller frees this string. */
return result;
}
static int