[Libvir] [PATCH] fix compilation if readline lib is not available
by Daniel Veillard
The current CVS code doesn't compile on RHEL5/F6 because readline lib
there require ncurses, and we removed that check earlier. Sor we find
the readline headers but the lib is not found. Unfortunately virsh.c
tests the availablility of the header to use readline, and link time failures
follow. The patch below:
- exports a READLINE_CFLAGS from configure if used
- use the READLINE_CFLAGS when compiling virsh.c
- change virsh.c to rely on this instead of the header test
- adds a message about readline usage at the end of configure
configure: Miscellaneous
configure:
configure: Debug: no
configure: Readline: yes
configure:
Another patch available soon should fix the readline library detection itself,
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 11 months
[Libvir] libvirt and dnsmasq question
by jack snodgrass
I have Fedora 8 witch contains:
libvirt-0.3.3-2.fc8
This version of libvirt automatically starts a copy of dnsmasq if it exists.
Is there a way to specify a dnsmasq.conf file that this will use or specify
command line options for dnsmasq when it is started? There are dnsmasq
options and config changes that I'd like to specify but I can't figure out
where this would be done. libvirt does not use the /etc/dnsmasq.conf file
or start dnsmasq using the normal init scripts.
Thanks - jack
16 years, 11 months
[Libvir] gnulib: take2, trunk-relative patch
by Jim Meyering
Here's the complete patch (but still none of the new files), rebased
and relative to the trunk. As before, this passes "make distcheck".
And as Daniel Veillard noted, you'd need git.
However the next patch will cvs-add all of the bootstrap-imported
files, so you won't need git unless you want to try this particular patch.
-------------------------------------------------------------
Use gnulib, starting with its physmem and getaddrinfo modules.
New files go into these directories:
gnulib/lib
gnulib/m4
tests/gnulib
* bootstrap: A wrapper around gnulib-tool.
* configure.in: Invoke gl_EARLY and gl_INIT, being careful to put gl_EARLY
before any macro that uses AC_COMPILE_IFELSE.
(AC_OUTPUT): Add lib/Makefile and gl-tests/Makefile. Remove m4/Makefile.
* Makefile.am (SUBDIRS): Add gnulib/lib and tests/gnulib. Remove m4.
* m4/Makefile.am: Remove file. Not needed.
* src/Makefile.am (INCLUDES): Add -I$(top_srcdir)/gnulib/lib -I../gnulib/lib.
(LDADDS, libvirt_la_LIBADD): Add ../gnulib/lib/libgnu.la.
* src/nodeinfo.c: Include "physmem.h".
* qemud/qemud.c, src/remote_internal.c: Include "getaddrinfo.h".
(MEMINFO_PATH, linuxNodeInfoMemPopulate): Remove definitions.
(virNodeInfoPopulate): Use physmem_total, not linuxNodeInfoMemPopulate.
* tests/Makefile.am (INCLUDES): Add -I$(top_srcdir)/gnulib/lib -I../gnulib/lib.
(LDADDS): Add ../gnulib/lib/libgnu.la.
* qemud/Makefile.am (libvirtd_LDADD): Add ../gnulib/lib/libgnu.la.
* tests/nodeinfotest.c (linuxTestCompareFiles): No longer read total
memory from a file.
Update expected output not to include "Memory: NNNN"
* tests/nodeinfodata/linux-nodeinfo-1.txt:
* tests/nodeinfodata/linux-nodeinfo-2.txt:
* tests/nodeinfodata/linux-nodeinfo-3.txt:
* tests/nodeinfodata/linux-nodeinfo-4.txt:
* tests/nodeinfodata/linux-nodeinfo-5.txt:
* tests/nodeinfodata/linux-nodeinfo-6.txt:
* src/test.c [WITH_TEST]: Remove definition of _GNU_SOURCE that
would conflict with the one now in "config.h".
* autogen.sh: Add -I gnulib/m4.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
Makefile.am | 5 +-
autogen.sh | 2 +-
bootstrap | 108 +++++++++++++++++++++++++++++++
configure.in | 11 ++-
m4/Makefile.am | 3 -
qemud/Makefile.am | 3 +-
qemud/qemud.c | 1 +
src/Makefile.am | 8 ++-
src/nodeinfo.c | 55 +++-------------
src/remote_internal.c | 1 +
src/test.c | 2 -
tests/Makefile.am | 2 +
tests/nodeinfodata/linux-nodeinfo-1.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-2.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-3.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-4.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-5.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-6.txt | 2 +-
tests/nodeinfotest.c | 23 ++-----
19 files changed, 151 insertions(+), 85 deletions(-)
create mode 100755 bootstrap
delete mode 100644 m4/Makefile.am
diff --git a/Makefile.am b/Makefile.am
index eaa204e..1f2ca52 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,8 +1,9 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = src qemud proxy include docs @PYTHON_SUBDIR@ tests po m4 scripts
+SUBDIRS = gnulib/lib src qemud proxy include docs @PYTHON_SUBDIR@ \
+ tests/gnulib tests po scripts
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I m4 -I gnulib/m4
EXTRA_DIST = libvirt.spec.in libvirt.spec COPYING.LIB \
libvirt.pc.in libvirt.pc TODO AUTHORS ChangeLog \
diff --git a/autogen.sh b/autogen.sh
index 97b636d..3bcffd3 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -57,7 +57,7 @@ fi
autopoint --force
#rm -rf m4
libtoolize --copy --force
-aclocal -I m4
+aclocal -I m4 -I gnulib/m4
autoheader
automake --add-missing
autoconf
diff --git a/bootstrap b/bootstrap
new file mode 100755
index 0000000..ca186bd
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,108 @@
+#!/bin/sh
+# Run this after autogen.sh, to pull in all of the gnulib-related bits.
+# It's important to run *after* autogen.sh, since it updates some of
+# the same files autogen.sh does, yet those from gnulib are newer,
+# and match the tests. So if a gnulib bug has been fixed since the
+# snapshot taken for whatever gettext release you're using, yet you
+# run "make check" against the wrong version, the corresponding unit
+# test in gl-tests/ may well fail.
+
+usage() {
+ echo >&2 "\
+Usage: $0 [OPTION]...
+Bootstrap this package from the checked-out sources.
+
+Options:
+ --gnulib-srcdir=DIRNAME Specify the local directory where gnulib
+ sources reside. Use this if you already
+ have gnulib sources on your machine, and
+ do not want to waste your bandwidth downloading
+ them again.
+
+If the file bootstrap.conf exists in the current working directory, its
+contents are read as shell variables to configure the bootstrap.
+
+Running without arguments will suffice in most cases.
+"
+}
+
+for option
+do
+ case $option in
+ --help)
+ usage
+ exit;;
+ --gnulib-srcdir=*)
+ GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
+ *)
+ echo >&2 "$0: $option: unknown option"
+ exit 1;;
+ esac
+done
+
+cleanup_gnulib() {
+ st=$?
+ rm -fr .gnulib
+ exit $st
+}
+
+case ${GNULIB_SRCDIR--} in
+-)
+ if [ ! -d gnulib ]; then
+ echo "$0: getting gnulib files..."
+
+ trap cleanup_gnulib 1 2 13 15
+
+ git clone --depth 1 git://git.sv.gnu.org/gnulib .gnulib ||
+ cleanup_gnulib
+
+ trap - 1 2 13 15
+ fi
+ GNULIB_SRCDIR=.gnulib
+esac
+
+gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
+<$gnulib_tool || exit
+
+# Tell gnulib to:
+# put tests in new tests/gnulib/ dir
+# put *.m4 files in new gnulib/m4/ dir
+# put *.[ch] files in new gnulib/lib/ dir.
+# With --avoid=snprintf, we drop support for systems (many!) with
+# losing snprintf but pull in about 30 fewer files
+# With the current gnulib and gettext-0.17, the following
+# files are added to m4/ by both. But gnulib is stable enough
+# and gettext-0.16.1 is new enough that they are identical.
+# compiler-flags.m4
+# inttypes_h.m4
+# longlong.m4
+# size_max.m4
+# stdint_h.m4
+# wchar_t.m4
+# wint_t.m4
+# xsize.m4
+
+# Note that if we don't exclude the snprintf module, there are two tests
+# that have incompatible licenses, so we would have to exclude them. Even
+# excluding those two test modules, find reports a total of 94 added files.
+# Yes, snprintf has some heavy-duty dependents.
+# --avoid=snprintf-tests
+# --avoid=vasnprintf-tests
+
+avoid='--avoid=snprintf'
+
+avoid='
+ --avoid=snprintf-tests
+ --avoid=vasnprintf-tests
+'
+
+$gnulib_tool \
+ --lgpl \
+ $avoid \
+ --avoid=snprintf-tests \
+ --avoid=vasnprintf-tests \
+ --with-tests \
+ --m4-base=gnulib/m4 \
+ --source-base=gnulib/lib \
+ --tests-base=tests/gnulib \
+ --import physmem getaddrinfo
diff --git a/configure.in b/configure.in
index 6cd7fe2..0cc8b6d 100644
--- a/configure.in
+++ b/configure.in
@@ -28,11 +28,15 @@ AVAHI_REQUIRED="0.6.0"
dnl Checks for C compiler.
AC_PROG_CC
-AM_PROG_CC_STDC
-AC_C_CONST
AC_PROG_INSTALL
AC_PROG_CPP
+gl_EARLY
+gl_INIT
+
+AM_PROG_CC_STDC
+AC_C_CONST
+
dnl Make sure we have an ANSI compiler
AM_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)
@@ -555,11 +559,12 @@ cp COPYING.LIB COPYING
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
docs/examples/Makefile docs/devhelp/Makefile \
docs/examples/python/Makefile \
+ gnulib/lib/Makefile tests/gnulib/Makefile \
libvirt.pc libvirt.spec \
po/Makefile.in scripts/Makefile \
include/libvirt/Makefile include/libvirt/libvirt.h \
python/Makefile python/tests/Makefile \
- qemud/Makefile m4/Makefile \
+ qemud/Makefile \
tests/Makefile proxy/Makefile \
tests/xml2sexprdata/Makefile \
tests/sexpr2xmldata/Makefile \
diff --git a/m4/Makefile.am b/m4/Makefile.am
deleted file mode 100644
index 188b2fe..0000000
--- a/m4/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-
-EXTRA_DIST = compiler-flags.m4
-
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index 1737176..7e3b694 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -27,6 +27,7 @@ libvirtd_SOURCES = \
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirtd_CFLAGS = \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I$(top_srcdir)/include -I$(top_builddir)/include \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) \
$(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
@@ -37,7 +38,7 @@ libvirtd_CFLAGS = \
libvirtd_LDFLAGS = $(WARN_CFLAGS) $(LIBXML_LIBS) $(GNUTLS_LIBS)
libvirtd_DEPENDENCIES = ../src/libvirt.la
-libvirtd_LDADD = ../src/libvirt.la
+libvirtd_LDADD = ../src/libvirt.la ../gnulib/lib/libgnu.la
if HAVE_AVAHI
libvirtd_SOURCES += mdns.c mdns.h
diff --git a/qemud/qemud.c b/qemud/qemud.c
index f88ed42..caccd29 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -53,6 +53,7 @@
#include <libvirt/virterror.h>
#include "internal.h"
+#include "getaddrinfo.h"
#include "../src/internal.h"
#include "../src/remote_internal.h"
#include "../src/conf.h"
diff --git a/src/Makefile.am b/src/Makefile.am
index 52ffbaf..f9a2308 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,8 @@
## Process this file with automake to produce Makefile.in
-INCLUDES = -I$(top_builddir)/include \
+INCLUDES = \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
+ -I../include \
-I@top_srcdir@/include \
-I@top_srcdir@/qemud \
$(LIBXML_CFLAGS) \
@@ -14,7 +16,7 @@ INCLUDES = -I$(top_builddir)/include \
$(WARN_CFLAGS) \
$(LIBVIRT_FEATURES)
DEPS = libvirt.la
-LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la
+LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../gnulib/lib/libgnu.la
VIRSH_LIBS = @VIRSH_LIBS@
confdir = $(sysconfdir)/libvirt/
@@ -60,7 +62,7 @@ SERVER_SOURCES = \
libvirt_la_SOURCES = $(CLIENT_SOURCES) $(SERVER_SOURCES)
libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(LTLIBOBJS) \
- @CYGWIN_EXTRA_LIBADD@
+ @CYGWIN_EXTRA_LIBADD@ ../gnulib/lib/libgnu.la
libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \
-version-info @LIBVIRT_VERSION_INFO@ \
$(COVERAGE_CFLAGS:-f%=-Wc,-f%) \
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index a0a26eb..2ef49cb 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -29,14 +29,14 @@
#include <ctype.h>
#include "nodeinfo.h"
+#include "physmem.h"
#ifdef __linux__
-#define MEMINFO_PATH "/proc/meminfo"
#define CPUINFO_PATH "/proc/cpuinfo"
/* NB, these are not static as we need to call them from testsuite */
-int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo);
-int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo, virNodeInfoPtr nodeinfo);
+int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo,
+ virNodeInfoPtr nodeinfo);
int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo) {
char line[1024];
@@ -114,44 +114,11 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
return 0;
}
-
-int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo,
- virNodeInfoPtr nodeinfo) {
- char line[1024];
-
- nodeinfo->memory = 0;
-
- while (fgets(line, sizeof(line), meminfo) != NULL) {
- if (STREQLEN(line, "MemTotal:", 9)) {
- char *p;
- unsigned int ui;
- if (xstrtol_ui(line + 10, &p, 10, &ui) == 0
- && (*p == '\0' || isspace(*p))) {
- nodeinfo->memory = ui;
- break;
- }
- }
- }
- if (!nodeinfo->memory) {
- __virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "no memory found");
- return -1;
- }
-
- return 0;
-}
-
-
#endif
int virNodeInfoPopulate(virConnectPtr conn,
virNodeInfoPtr nodeinfo) {
struct utsname info;
-#ifdef __linux__
- int ret;
- FILE *cpuinfo, *meminfo;
-#endif
if (uname(&info) < 0) {
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
@@ -164,7 +131,9 @@ int virNodeInfoPopulate(virConnectPtr conn,
nodeinfo->model[sizeof(nodeinfo->model)-1] = '\0';
#ifdef __linux__
- cpuinfo = fopen(CPUINFO_PATH, "r");
+ {
+ int ret;
+ FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
@@ -176,17 +145,11 @@ int virNodeInfoPopulate(virConnectPtr conn,
if (ret < 0)
return -1;
- meminfo = fopen(MEMINFO_PATH, "r");
- if (!meminfo) {
- __virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "cannot open %s %s", MEMINFO_PATH, strerror(errno));
- return -1;
- }
- ret = linuxNodeInfoMemPopulate(conn, meminfo, nodeinfo);
- fclose(meminfo);
+ /* Convert to KB. */
+ nodeinfo->memory = physmem_total () / 1024;
return ret;
+ }
#else
/* XXX Solaris will need an impl later if they port QEMU driver */
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
diff --git a/src/remote_internal.c b/src/remote_internal.c
index a8227f3..275405a 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -52,6 +52,7 @@
#include "internal.h"
#include "driver.h"
+#include "getaddrinfo.h"
#include "remote_internal.h"
#include "remote_protocol.h"
diff --git a/src/test.c b/src/test.c
index 010ea15..bab280f 100644
--- a/src/test.c
+++ b/src/test.c
@@ -25,8 +25,6 @@
#ifdef WITH_TEST
-#define _GNU_SOURCE /* for asprintf */
-
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 512162b..8220e1b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,6 +11,7 @@ SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata xencapsdat
LIBVIRT = $(wildcard $(top_builddir)/src/.libs/libvirt_la-*.o)
INCLUDES = \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I$(top_builddir)/include \
-I$(top_builddir)/src \
-I$(top_srcdir)/include \
@@ -29,6 +30,7 @@ LDADDS = \
$(GNUTLS_LIBS) \
$(WARN_CFLAGS) \
$(LIBVIRT) \
+ ../gnulib/lib/libgnu.la \
$(COVERAGE_LDFLAGS)
EXTRA_DIST = \
diff --git a/tests/nodeinfodata/linux-nodeinfo-1.txt b/tests/nodeinfodata/linux-nodeinfo-1.txt
index 1a38ad1..e52e20a 100644
--- a/tests/nodeinfodata/linux-nodeinfo-1.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-1.txt
@@ -1 +1 @@
-CPUs: 2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Memory: 2053960
+CPUs: 2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-2.txt b/tests/nodeinfodata/linux-nodeinfo-2.txt
index 1c31a0c..12e819b 100644
--- a/tests/nodeinfodata/linux-nodeinfo-2.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-2.txt
@@ -1 +1 @@
-CPUs: 2, MHz: 2211, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Memory: 4059540
+CPUs: 2, MHz: 2211, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-3.txt b/tests/nodeinfodata/linux-nodeinfo-3.txt
index e2cc841..d285781 100644
--- a/tests/nodeinfodata/linux-nodeinfo-3.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-3.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1595, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1595, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-4.txt b/tests/nodeinfodata/linux-nodeinfo-4.txt
index 2c75ea3..991d4f9 100644
--- a/tests/nodeinfodata/linux-nodeinfo-4.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-4.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-5.txt b/tests/nodeinfodata/linux-nodeinfo-5.txt
index 01fee52..dce7ada 100644
--- a/tests/nodeinfodata/linux-nodeinfo-5.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-5.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 2814, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 2814, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-6.txt b/tests/nodeinfodata/linux-nodeinfo-6.txt
index a7a2cfe..75cdaa9 100644
--- a/tests/nodeinfodata/linux-nodeinfo-6.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-6.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 7275cc3..fb563b5 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -21,14 +21,13 @@ static char *abs_top_srcdir;
#ifdef __linux__
extern int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo);
-extern int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo, virNodeInfoPtr nodeinfo);
-static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofile, const char *outputfile) {
+static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) {
char actualData[MAX_FILE];
char expectData[MAX_FILE];
char *expect = &expectData[0];
virNodeInfo nodeinfo;
- FILE *cpuinfo, *meminfo;
+ FILE *cpuinfo;
if (virtTestLoadFile(outputfile, &expect, MAX_FILE) < 0)
return -1;
@@ -42,19 +41,10 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofil
}
fclose(cpuinfo);
- meminfo = fopen(meminfofile, "r");
- if (!meminfo)
- return -1;
- if (linuxNodeInfoMemPopulate(NULL, meminfo, &nodeinfo) < 0) {
- fclose(meminfo);
- return -1;
- }
- fclose(meminfo);
-
snprintf(actualData, MAX_FILE,
- "CPUs: %u, MHz: %u, Nodes: %u, Sockets: %u, Cores: %u, Threads: %u, Memory: %lu\n",
+ "CPUs: %u, MHz: %u, Nodes: %u, Sockets: %u, Cores: %u, Threads: %u\n",
nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets,
- nodeinfo.cores, nodeinfo.threads, nodeinfo.memory);
+ nodeinfo.cores, nodeinfo.threads);
if (STRNEQ(actualData, expectData)) {
if (getenv("DEBUG_TESTS")) {
@@ -70,15 +60,12 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofil
static int linuxTestNodeInfo(const void *data) {
char cpuinfo[PATH_MAX];
- char meminfo[PATH_MAX];
char output[PATH_MAX];
snprintf(cpuinfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.cpuinfo",
abs_top_srcdir, (const char*)data);
- snprintf(meminfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.meminfo",
- abs_top_srcdir, (const char*)data);
snprintf(output, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.txt",
abs_top_srcdir, (const char*)data);
- return linuxTestCompareFiles(cpuinfo, meminfo, output);
+ return linuxTestCompareFiles(cpuinfo, output);
}
#endif
--
1.5.3.6.950.g92b7b
16 years, 11 months
[Libvir] gnulib: done (first two modules)
by Jim Meyering
I've checked in all of the changes to let libvirt use
the first two modules from gnulib.
That exposed the fact that gnulib's gl_INIT macro depends
on autoconf-2.59c or newer for its definition of the m4_foreach_w
macro. Here's a kludgey work-around patch, just committed, to
fix build failure for developers who are stuck using such old tools:
(also removed some trailing blanks)
Accommodate developers using autoconf-2.59.
* configure.in (m4_foreach_w): Define if not defined.
I'll propose the proper change (in gnulib) tomorrow.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
ChangeLog | 5 +++++
configure.in | 17 ++++++++++++-----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4b3c266..302706c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Dec 5 23:57:53 CET 2007 Jim Meyering <meyering(a)redhat.com>
+
+ Accommodate developers using autoconf-2.59.
+ * configure.in (m4_foreach_w): Define if not defined.
+
Wed Dec 5 22:38:18 CET 2007 Jim Meyering <meyering(a)redhat.com>
Include "config.h".
diff --git a/configure.in b/configure.in
index a7f692e..8d2a143 100644
--- a/configure.in
+++ b/configure.in
@@ -33,6 +33,13 @@ AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_CPP
+dnl gl_INIT uses m4_foreach_w, yet that is not defined in autoconf-2.59.
+dnl In order to accommodate developers with such old tools, here's a
+dnl replacement definition.
+m4_ifndef([m4_foreach_w],
+ [m4_define([m4_foreach_w],
+ [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
+
gl_EARLY
gl_INIT
@@ -289,8 +296,8 @@ LIBXML_LIBS=""
LIBXML_FOUND="no"
AC_ARG_WITH(libxml, [ --with-libxml=[PFX] libxml2 location])
-if test "z$with_libxml" = "zno" ; then
- AC_MSG_CHECKING(for libxml2 libraries >= $LIBXML_REQUIRED)
+if test "z$with_libxml" = "zno" ; then
+ AC_MSG_CHECKING(for libxml2 libraries >= $LIBXML_REQUIRED)
AC_MSG_ERROR(libxml2 >= $LIBXML_REQUIRED is required for libvirt)
elif test "z$with_libxml" = "z" -a "x$PKG_CONFIG" != "x" ; then
PKG_CHECK_EXISTS(libxml-2.0,[LIBXML_FOUND=yes])
@@ -299,7 +306,7 @@ elif test "z$with_libxml" = "z" -a "x$PKG_CONFIG" != "x" ; then
fi
fi
if test "z$LIBXML_FOUND" = "zno" ; then
- if test "z$with_libxml" != "z" ; then
+ if test "z$with_libxml" != "z" ; then
LIBXML_CONFIG=$with_libxml/bin/$LIBXML_CONFIG
fi
AC_MSG_CHECKING(libxml2 $LIBXML_CONFIG >= $LIBXML_REQUIRED )
@@ -442,8 +449,8 @@ AC_SUBST(AVAHI_LIBS)
dnl virsh libraries
AC_CHECK_HEADERS([readline/readline.h])
-AC_CHECK_LIB(readline, main,
- [VIRSH_LIBS="$VIRSH_LIBS -lreadline"],
+AC_CHECK_LIB(readline, main,
+ [VIRSH_LIBS="$VIRSH_LIBS -lreadline"],
[AC_MSG_WARN([readline library not found])],
[$VIRSH_LIBS])
AC_SUBST(VIRSH_LIBS)
--
1.5.3.7.1006.g8c6a6
16 years, 11 months
[Libvir] Fix compilation --without-sasl
by Richard W.M. Jones
Fixes compilation when ./configure --without-sasl.
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
16 years, 11 months
[Libvir] [PATCH] Detect heap allocation failure; factor out some duplication.
by Jim Meyering
I spotted a few unchecked heap allocations (strdup, malloc, calloc)
in qemud.c and have fixed it so such failure evokes a proper diagnostic
rather than e.g., a segfault.
I've also arranged to free some of the memory upon failure,
but not all (see comments for why).
In spite of those additions, this patch factors out enough
duplication that the net change is to remove a few lines from the
file. Although in general I prefer to factor things out into
separate functions, in this case, it seemed better to use macros.
Wed Nov 28 14:16:17 CET 2007 Jim Meyering <meyering(a)redhat.com>
Detect heap allocation failure; factor out some duplication.
* qemud/qemud.c (mdns_name, tls_allowed_ip_list, tls_allowed_dn_list):
Remove "const", now that we free these.
(remoteCheckDN, remoteCheckAccess): Adapt to const removal.
(qemudDispatchServer): Check for heap allocation failure.
CHECK_TYPE, GET_CONF_INT, GET_CONF_STR, GET_CONF_STR_LIST):
New and changed macros.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
qemud/qemud.c | 247 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 121 insertions(+), 126 deletions(-)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index 5f76a26..34ab815 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -79,13 +79,13 @@ static int unix_sock_ro_perms = 0777; /* Allow world */
#ifdef HAVE_AVAHI
static int mdns_adv = 1;
-static const char *mdns_name = NULL;
+static char *mdns_name = NULL;
#endif
static int tls_no_verify_certificate = 0;
static int tls_no_verify_address = 0;
-static const char **tls_allowed_ip_list = 0;
-static const char **tls_allowed_dn_list = 0;
+static char **tls_allowed_ip_list = NULL;
+static char **tls_allowed_dn_list = NULL;
static const char *key_file = LIBVIRT_SERVERKEY;
static const char *cert_file = LIBVIRT_SERVERCERT;
@@ -840,7 +840,7 @@ remoteCheckDN (gnutls_x509_crt_t cert)
{
char name[256];
size_t namesize = sizeof name;
- const char **wildcards;
+ char **wildcards;
int err;
err = gnutls_x509_crt_get_dn (cert, name, &namesize);
@@ -959,7 +959,7 @@ static int
remoteCheckAccess (struct qemud_client *client)
{
char addr[NI_MAXHOST];
- const char **wildcards;
+ char **wildcards;
int found, err;
/* Verify client certificate. */
@@ -1044,6 +1044,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
}
client = calloc(1, sizeof(struct qemud_client));
+ if (client == NULL)
+ goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC;
client->fd = fd;
client->readonly = sock->readonly;
@@ -1523,31 +1525,38 @@ remoteReadConfigFile (const char *filename)
virConfValuePtr p;
-#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \
- qemudLog (QEMUD_ERR, \
- "remoteReadConfigFile: %s: %s: expected type " #typ "\n", \
- filename, (name)); \
- return -1; \
- }
-
- p = virConfGetValue (conf, "listen_tls");
- CHECK_TYPE ("listen_tls", VIR_CONF_LONG);
- listen_tls = p ? p->l : listen_tls;
-
- p = virConfGetValue (conf, "listen_tcp");
- CHECK_TYPE ("listen_tcp", VIR_CONF_LONG);
- listen_tcp = p ? p->l : listen_tcp;
-
- p = virConfGetValue (conf, "tls_port");
- CHECK_TYPE ("tls_port", VIR_CONF_STRING);
- tls_port = p ? strdup (p->str) : tls_port;
-
- p = virConfGetValue (conf, "tcp_port");
- CHECK_TYPE ("tcp_port", VIR_CONF_STRING);
- tcp_port = p ? strdup (p->str) : tcp_port;
-
- p = virConfGetValue (conf, "unix_sock_group");
- CHECK_TYPE ("unix_sock_group", VIR_CONF_STRING);
+#define CHECK_TYPE(p, filename, conf, var_name, Type) \
+ do { \
+ (p) = virConfGetValue ((conf), #Type); \
+ if ((p) && (p)->type != (Type)) { \
+ qemudLog (QEMUD_ERR, \
+ "remoteReadConfigFile: %s: %s:" \
+ " expected type " #Type "\n", \
+ filename, #var_name); \
+ goto free_and_fail; \
+ } \
+ } while (0)
+
+#define GET_CONF_INT(p, filename, conf, var_name) \
+ do { \
+ CHECK_TYPE(p, filename, conf, var_name, VIR_CONF_LONG); \
+ if (p) \
+ (var_name) = p->l; \
+ } while (0)
+
+#define GET_CONF_STR(p, filename, conf, var_name) \
+ do { \
+ CHECK_TYPE(p, filename, conf, var_name, VIR_CONF_STRING); \
+ if (p) { \
+ if (!((var_name) = strdup ((p)->str))) \
+ goto diagnose_alloc_failure_and_fail; \
+ } \
+ } while (0)
+
+ GET_CONF_STR (p, filename, conf, tls_port);
+ GET_CONF_STR (p, filename, conf, tcp_port);
+
+ CHECK_TYPE (p, filename, conf, unix_sock_group, VIR_CONF_STRING);
if (p && p->str) {
if (getuid() != 0) {
qemudLog (QEMUD_WARN, "Cannot set group when not running as root");
@@ -1561,8 +1570,7 @@ remoteReadConfigFile (const char *filename)
}
}
- p = virConfGetValue (conf, "unix_sock_ro_perms");
- CHECK_TYPE ("unix_sock_ro_perms", VIR_CONF_STRING);
+ GET_CONF_INT (p, filename, conf, unix_sock_ro_perms);
if (p && p->str) {
if (xstrtol_i(p->str, NULL, 8, &unix_sock_ro_perms) != 0) {
qemudLog (QEMUD_ERR, "Failed to parse mode '%s'", p->str);
@@ -1570,8 +1578,7 @@ remoteReadConfigFile (const char *filename)
}
}
- p = virConfGetValue (conf, "unix_sock_rw_perms");
- CHECK_TYPE ("unix_sock_rw_perms", VIR_CONF_STRING);
+ GET_CONF_INT (p, filename, conf, unix_sock_rw_perms);
if (p && p->str) {
if (xstrtol_i(p->str, NULL, 8, &unix_sock_rw_perms) != 0) {
qemudLog (QEMUD_ERR, "Failed to parse mode '%s'", p->str);
@@ -1580,107 +1587,95 @@ remoteReadConfigFile (const char *filename)
}
#ifdef HAVE_AVAHI
- p = virConfGetValue (conf, "mdns_adv");
- CHECK_TYPE ("mdns_adv", VIR_CONF_LONG);
- mdns_adv = p ? p->l : mdns_adv;
-
- p = virConfGetValue (conf, "mdns_name");
- CHECK_TYPE ("mdns_name", VIR_CONF_STRING);
- mdns_name = p ? strdup (p->str) : NULL;
+ GET_CONF_INT (p, filename, conf, mdns_adv);
+ GET_CONF_STR (p, filename, conf, mdns_name);
#endif
- p = virConfGetValue (conf, "tls_no_verify_certificate");
- CHECK_TYPE ("tls_no_verify_certificate", VIR_CONF_LONG);
- tls_no_verify_certificate = p ? p->l : tls_no_verify_certificate;
-
- p = virConfGetValue (conf, "tls_no_verify_address");
- CHECK_TYPE ("tls_no_verify_address", VIR_CONF_LONG);
- tls_no_verify_address = p ? p->l : tls_no_verify_address;
-
- p = virConfGetValue (conf, "key_file");
- CHECK_TYPE ("key_file", VIR_CONF_STRING);
- key_file = p ? strdup (p->str) : key_file;
-
- p = virConfGetValue (conf, "cert_file");
- CHECK_TYPE ("cert_file", VIR_CONF_STRING);
- cert_file = p ? strdup (p->str) : cert_file;
-
- p = virConfGetValue (conf, "ca_file");
- CHECK_TYPE ("ca_file", VIR_CONF_STRING);
- ca_file = p ? strdup (p->str) : ca_file;
-
- p = virConfGetValue (conf, "crl_file");
- CHECK_TYPE ("crl_file", VIR_CONF_STRING);
- crl_file = p ? strdup (p->str) : crl_file;
-
- p = virConfGetValue (conf, "tls_allowed_dn_list");
- if (p) {
- switch (p->type) {
- case VIR_CONF_STRING:
- tls_allowed_dn_list = malloc (2 * sizeof (char *));
- tls_allowed_dn_list[0] = strdup (p->str);
- tls_allowed_dn_list[1] = 0;
- break;
+ GET_CONF_INT (p, filename, conf, tls_no_verify_certificate);
+ GET_CONF_INT (p, filename, conf, tls_no_verify_address);
+
+ GET_CONF_STR (p, filename, conf, key_file);
+ GET_CONF_STR (p, filename, conf, cert_file);
+ GET_CONF_STR (p, filename, conf, ca_file);
+ GET_CONF_STR (p, filename, conf, crl_file);
+
+#define GET_CONF_STR_LIST(List_var) \
+ do { \
+ p = virConfGetValue (conf, #List_var); \
+ if (p) { \
+ switch (p->type) { \
+ case VIR_CONF_STRING: \
+ if (!((List_var) = malloc (2 * sizeof (char *)))) \
+ goto free_and_fail; \
+ if (!((List_var)[0] = strdup (p->str))) \
+ goto free_and_fail; \
+ (List_var)[1] = NULL; \
+ break; \
+ \
+ case VIR_CONF_LIST: { \
+ int i, len = 0; \
+ virConfValuePtr pp; \
+ for (pp = p->list; pp; pp = p->next) \
+ len++; \
+ if (!((List_var) = malloc ((1+len) * sizeof (char *)))) \
+ goto free_and_fail; \
+ for (i = 0, pp = p->list; pp; ++i, pp = p->next) { \
+ if (pp->type != VIR_CONF_STRING) { \
+ qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: %s: " \
+ "must be a string or list of strings\n", \
+ filename, #List_var); \
+ goto free_and_fail; \
+ } \
+ if (!((List_var)[i] = strdup (pp->str))) \
+ goto free_and_fail; \
+ } \
+ (List_var)[i] = NULL; \
+ break; \
+ } \
+ \
+ default: \
+ qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: %s: " \
+ "must be a string or list of strings\n", \
+ filename, #List_var); \
+ goto free_and_fail; \
+ } \
+ } \
+ } while (0)
+
+ GET_CONF_STR_LIST (tls_allowed_dn_list);
+ GET_CONF_STR_LIST (tls_allowed_ip_list);
- case VIR_CONF_LIST: {
- int i, len = 0;
- virConfValuePtr pp;
- for (pp = p->list; pp; pp = p->next)
- len++;
- tls_allowed_dn_list =
- malloc ((1+len) * sizeof (char *));
- for (i = 0, pp = p->list; pp; ++i, pp = p->next) {
- if (pp->type != VIR_CONF_STRING) {
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: tls_allowed_dn_list: should be a string or list of strings\n", filename);
- return -1;
- }
- tls_allowed_dn_list[i] = strdup (pp->str);
- }
- tls_allowed_dn_list[i] = 0;
- break;
- }
+ virConfFree (conf);
+ return 0;
- default:
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: tls_allowed_dn_list: should be a string or list of strings\n", filename);
- return -1;
- }
- }
+ diagnose_alloc_failure_and_fail:
+ qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s\n", strerror (errno));
- p = virConfGetValue (conf, "tls_allowed_ip_list");
- if (p) {
- switch (p->type) {
- case VIR_CONF_STRING:
- tls_allowed_ip_list = malloc (2 * sizeof (char *));
- tls_allowed_ip_list[0] = strdup (p->str);
- tls_allowed_ip_list[1] = 0;
- break;
+ free_and_fail:
+ free (mdns_name);
+ mdns_name = NULL;
- case VIR_CONF_LIST: {
- int i, len = 0;
- virConfValuePtr pp;
- for (pp = p->list; pp; pp = p->next)
- len++;
- tls_allowed_ip_list =
- malloc ((1+len) * sizeof (char *));
- for (i = 0, pp = p->list; pp; ++i, pp = p->next) {
- if (pp->type != VIR_CONF_STRING) {
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: tls_allowed_ip_list: should be a string or list of strings\n", filename);
- return -1;
- }
- tls_allowed_ip_list[i] = strdup (pp->str);
- }
- tls_allowed_ip_list[i] = 0;
- break;
- }
+ /* Don't bother trying to free tcp_port, tls_port, key_file, cert_file,
+ ca_file, or crl_file, since they are initialized to non-malloc'd
+ strings. Besides, these are static variables, and callers are
+ unlikely to call this function more than once, so there wouldn't
+ even be a real leak. */
- default:
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: tls_allowed_ip_list: should be a string or list of strings\n", filename);
- return -1;
- }
+ if (tls_allowed_ip_list) {
+ char *t;
+ for (t = *tls_allowed_ip_list; t; t++)
+ free (t);
+ tls_allowed_ip_list = NULL;
}
- virConfFree (conf);
- return 0;
+ if (tls_allowed_dn_list) {
+ char *t;
+ for (t = *tls_allowed_dn_list; t; t++)
+ free (t);
+ tls_allowed_dn_list = NULL;
+ }
+
+ return -1;
}
/* Print command-line usage. */
--
1.5.3.6.961.gecf4
16 years, 11 months
[Libvir] gnulib, take2: incremental
by Jim Meyering
Here is the first of two patches. For now, neither includes
all of the new files. That one's coming up shortly.
First the incremental one, to show you what's changed since last time:
(so you would apply this on top of the patch from last night)
I'll post the combined, (i.e., full, trunk-relative) one separately.
Adapt to change directory names:
Now we use these:
gnulib/lib
gnulib/m4
tests/gnulib
* Makefile.am (SUBDIRS): Change dir names.
* autogen.sh: Add -I gnulib/m4.
* bootstrap: Don't exclude snprintf after all. Define cleanup function.
* configure.in: adjust dir/Makefile names.
* qemud/Makefile.am: Adjust -I and .a paths.
* src/Makefile.am: Likewise.
* tests/Makefile.am: Likewise.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
Makefile.am | 6 +++---
autogen.sh | 2 +-
bootstrap | 34 ++++++++++++++++++++++++++--------
configure.in | 2 +-
qemud/Makefile.am | 4 ++--
src/Makefile.am | 6 +++---
tests/Makefile.am | 4 ++--
7 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index fcf0eb6..1f2ca52 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,9 +1,9 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = lib src qemud proxy include docs @PYTHON_SUBDIR@ \
- gl-tests tests po scripts
+SUBDIRS = gnulib/lib src qemud proxy include docs @PYTHON_SUBDIR@ \
+ tests/gnulib tests po scripts
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I m4 -I gnulib/m4
EXTRA_DIST = libvirt.spec.in libvirt.spec COPYING.LIB \
libvirt.pc.in libvirt.pc TODO AUTHORS ChangeLog \
diff --git a/autogen.sh b/autogen.sh
index 97b636d..3bcffd3 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -57,7 +57,7 @@ fi
autopoint --force
#rm -rf m4
libtoolize --copy --force
-aclocal -I m4
+aclocal -I m4 -I gnulib/m4
autoheader
automake --add-missing
autoconf
diff --git a/bootstrap b/bootstrap
index b49378d..ca186bd 100755
--- a/bootstrap
+++ b/bootstrap
@@ -40,6 +40,12 @@ do
esac
done
+cleanup_gnulib() {
+ st=$?
+ rm -fr .gnulib
+ exit $st
+}
+
case ${GNULIB_SRCDIR--} in
-)
if [ ! -d gnulib ]; then
@@ -47,22 +53,23 @@ case ${GNULIB_SRCDIR--} in
trap cleanup_gnulib 1 2 13 15
- git clone --depth 1 git://git.sv.gnu.org/gnulib ||
+ git clone --depth 1 git://git.sv.gnu.org/gnulib .gnulib ||
cleanup_gnulib
trap - 1 2 13 15
fi
- GNULIB_SRCDIR=gnulib
+ GNULIB_SRCDIR=.gnulib
esac
gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
<$gnulib_tool || exit
# Tell gnulib to:
-# put tests in new gl-tests/ dir
-# put m4/*.m4 files in existing m4/ dir
-# lib/*.[ch] files in new lib/ dir.
-# With --avoid=snprintf, we pull in about 30 fewer files
+# put tests in new tests/gnulib/ dir
+# put *.m4 files in new gnulib/m4/ dir
+# put *.[ch] files in new gnulib/lib/ dir.
+# With --avoid=snprintf, we drop support for systems (many!) with
+# losing snprintf but pull in about 30 fewer files
# With the current gnulib and gettext-0.17, the following
# files are added to m4/ by both. But gnulib is stable enough
# and gettext-0.16.1 is new enough that they are identical.
@@ -82,9 +89,20 @@ gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
# --avoid=snprintf-tests
# --avoid=vasnprintf-tests
+avoid='--avoid=snprintf'
+
+avoid='
+ --avoid=snprintf-tests
+ --avoid=vasnprintf-tests
+'
+
$gnulib_tool \
--lgpl \
- --avoid=snprintf \
+ $avoid \
+ --avoid=snprintf-tests \
+ --avoid=vasnprintf-tests \
--with-tests \
- --tests-base=gl-tests \
+ --m4-base=gnulib/m4 \
+ --source-base=gnulib/lib \
+ --tests-base=tests/gnulib \
--import physmem getaddrinfo
diff --git a/configure.in b/configure.in
index 18a533f..2ab8411 100644
--- a/configure.in
+++ b/configure.in
@@ -566,7 +566,7 @@ cp COPYING.LIB COPYING
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
docs/examples/Makefile docs/devhelp/Makefile \
docs/examples/python/Makefile \
- lib/Makefile gl-tests/Makefile \
+ gnulib/lib/Makefile tests/gnulib/Makefile \
libvirt.pc libvirt.spec \
po/Makefile.in scripts/Makefile \
include/libvirt/Makefile include/libvirt/libvirt.h \
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index 267b43e..7e3b694 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -27,7 +27,7 @@ libvirtd_SOURCES = \
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirtd_CFLAGS = \
- -I$(top_srcdir)/lib -I../lib \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I$(top_srcdir)/include -I$(top_builddir)/include \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) \
$(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
@@ -38,7 +38,7 @@ libvirtd_CFLAGS = \
libvirtd_LDFLAGS = $(WARN_CFLAGS) $(LIBXML_LIBS) $(GNUTLS_LIBS)
libvirtd_DEPENDENCIES = ../src/libvirt.la
-libvirtd_LDADD = ../src/libvirt.la ../lib/libgnu.la
+libvirtd_LDADD = ../src/libvirt.la ../gnulib/lib/libgnu.la
if HAVE_AVAHI
libvirtd_SOURCES += mdns.c mdns.h
diff --git a/src/Makefile.am b/src/Makefile.am
index efea233..f9a2308 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in
INCLUDES = \
- -I$(top_srcdir)/lib -I../lib \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I../include \
-I@top_srcdir@/include \
-I@top_srcdir@/qemud \
@@ -16,7 +16,7 @@ INCLUDES = \
$(WARN_CFLAGS) \
$(LIBVIRT_FEATURES)
DEPS = libvirt.la
-LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../lib/libgnu.la
+LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../gnulib/lib/libgnu.la
VIRSH_LIBS = @VIRSH_LIBS@
confdir = $(sysconfdir)/libvirt/
@@ -62,7 +62,7 @@ SERVER_SOURCES = \
libvirt_la_SOURCES = $(CLIENT_SOURCES) $(SERVER_SOURCES)
libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(LTLIBOBJS) \
- @CYGWIN_EXTRA_LIBADD@ ../lib/libgnu.la
+ @CYGWIN_EXTRA_LIBADD@ ../gnulib/lib/libgnu.la
libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \
-version-info @LIBVIRT_VERSION_INFO@ \
$(COVERAGE_CFLAGS:-f%=-Wc,-f%) \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4de0c45..8220e1b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,7 @@ SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata xencapsdat
LIBVIRT = $(wildcard $(top_builddir)/src/.libs/libvirt_la-*.o)
INCLUDES = \
- -I$(top_srcdir)/lib -I../lib \
+ -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I$(top_builddir)/include \
-I$(top_builddir)/src \
-I$(top_srcdir)/include \
@@ -30,7 +30,7 @@ LDADDS = \
$(GNUTLS_LIBS) \
$(WARN_CFLAGS) \
$(LIBVIRT) \
- ../lib/libgnu.la \
+ ../gnulib/lib/libgnu.la \
$(COVERAGE_LDFLAGS)
EXTRA_DIST = \
--
1.5.3.6.950.g92b7b
16 years, 11 months
[Libvir] using gnulib: starting with the physmem and getaddrinfo modules
by Jim Meyering
Recently, I heard of two tricky portability problems in libvirt that
are easy to solve with gnulib. Of course, gnulib provides a lot more,
and is not exactly lightweight if you count "lines of code imported", but
once the framework (this patch) is installed, adding an additional module
is as easy as adding the module name to a list. Keep in mind that what
matters with a portability library is that it stay out of your way -- and
of course do its job well. To that end, gnulib has many per-module unit
tests. Since a large part of its job is portability, and insulating your
code from bugs (be they bugs in the very latest glibc printf functions, or
in the regexp library, or just protection against that crufty old SunOS4
free function that can't deal with NULL), it provides a mechanism to let
you conveniently include its self tests in your own package and run them
when users run "make check" for your project. This is pretty important,
so that if someone builds your package on an unusual or poorly-configured
system, often the gnulib tests will fail right away, and that will save
you the trouble of digging through your own package's code.
For those of you who don't know, gnulib is the GNU Portability Library.
http://www.gnu.org/software/gnulib/
and it is used in many widely-used packages:
http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=users.txt;hb=HEAD
Of course, there's no guarantee that the code is bug-free,
but in practice, the few bugs being fixed these days involve
portability to relatively unusual systems. With so many widely-used
packages using gnulib, you can imagine that if there are bugs, they
will be encountered, reported, and fixed pretty quickly.
One of the biggest advantages of using gnulib is that you can add
new modules and get all the benefits with *no* additional tweaking.
I.e., you don't have to write .m4 macros, modify configure.ac or
any Makefile.am. It just works. If something doesn't, or if the
documentation is unclear, you can report it to bug-gnulib(a)gnu.org
and usually get a fix or an explanation pretty quickly.
----------
Enough of the hype.
The first portability problem was to determine the total physical memory
available on the current system. Currently the code works only on
Linux-like systems that have /proc/meminfo of an expected form. However,
the gnulib physmem module handles 13 distinct types of systems and is
well tested:
http://www.gnu.org/software/gnulib/MODULES.html#module=physmem
The second portability problem was to find a robust and LGPL-compatible
getaddrinfo function to be used on systems lacking it. Here's the
gnulib module:
http://www.gnu.org/software/gnulib/MODULES.html#module=getaddrinfo
Once the few gnulib hooks are in your configure.ac and Makefile.am
files, there is very little extra work required to use the new
functions. In the case of physmem, just use the function and
include "physmem.h". For getaddrinfo, merely include "getaddrinfo.h"
from the two files that use the function.
This change brings in a lot of code, but many of the lib/.[ch] files
are used only on systems that lack some required functionality. For
example, the getaddrinfo.c file isn't even compiled when it's not
needed.
In the patch below, I've included a new script called bootstrap.
It is a wrapper around gnulib-tool that pulls into libvirt the
files selected by the (currently two) modules in use. Those new
files go in three places:
m4/*.m4
lib/*.[ch] and a few template .h.in files
gl-tests/ for unit test C programs and Bourne shell scripts
However, note that gettextize and libtoolize (run by autogen.sh)
also deposit many *.m4 files in m4. I compared and found that 8
of the files that are already pulled in by the *ize programs are
also pulled in (potentially newer versions) from gnulib. But currently,
using gettext-0.16.1 or gettext-0.17, there is no difference in any
of the overlapping files.
Re Licenses: the two modules (and all of their dependent modules)
are LGPL-compatible. This is enforced by running gnulib-tool
with the --lgpl option. If you were to request a module with
an incompatible license (say GPL or LGPLv3), it would fail.
----------------------
Here's the patch that shows what existing parts of libvirt have to
be modified to use these two new modules. To try it out, just apply
the patch and then run this:
./autogen.sh && ./bootstrap && make && make check
Running bootstrap creates the new lib/ and gl-tests/ directories.
Personally, I prefer not to add generated files to version control
systems, because it can lead to problems with version skew if all
developers don't use the same releases of the tools that do the
generating. Perhaps more importantly, when there are massive diffs in
the generated files, that can obscure real changes in non-generated parts
of the code. That already happens to me whenever the .po files change.
But if people prefer to add all of these imported files to CVS, just
say the word and I'll prepare the patch. If so, do you guys want the
gettextize- and libtoolize-added files to be version-controlled, now, too?
Use gnulib, starting with physmem and getaddrinfo modules.
* bootstrap: A wrapper around gnulib-tool.
* configure.in: Invoke gl_EARLY and gl_INIT, being careful to put gl_EARLY
before any macro that uses AC_COMPILE_IFELSE.
(AC_OUTPUT): Add lib/Makefile and gl-tests/Makefile. Remove m4/Makefile.
* Makefile.am (SUBDIRS): Add lib and gl-tests. Remove m4.
* m4/Makefile.am: Remove file. Not needed.
* src/Makefile.am (INCLUDES): Add -I$(top_srcdir)/lib -I../lib.
(LDADDS, libvirt_la_LIBADD): Add ../lib/libgnu.la.
* src/nodeinfo.c: Include "physmem.h".
* qemud/qemud.c, src/remote_internal.c: Include "getaddrinfo.h".
(MEMINFO_PATH, linuxNodeInfoMemPopulate): Remove definitions.
(virNodeInfoPopulate): Use physmem_total, not linuxNodeInfoMemPopulate.
* tests/Makefile.am (INCLUDES): Add -I$(top_srcdir)/lib -I../lib.
(LDADDS): Add ../lib/libgnu.la.
* qemud/Makefile.am (libvirtd_LDADD): Add ../lib/libgnu.la.
* tests/nodeinfotest.c (linuxTestCompareFiles): No longer read total
memory from a file.
Update expected output not to include "Memory: NNNN"
* tests/nodeinfodata/linux-nodeinfo-1.txt:
* tests/nodeinfodata/linux-nodeinfo-2.txt:
* tests/nodeinfodata/linux-nodeinfo-3.txt:
* tests/nodeinfodata/linux-nodeinfo-4.txt:
* tests/nodeinfodata/linux-nodeinfo-5.txt:
* tests/nodeinfodata/linux-nodeinfo-6.txt:
* src/test.c [WITH_TEST]: Remove definition of _GNU_SOURCE that
would conflict with the one now in "config.h".
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
Makefile.am | 3 +-
bootstrap | 90 +++++++++++++++++++++++++++++++
configure.in | 11 +++-
m4/Makefile.am | 3 -
qemud/Makefile.am | 3 +-
qemud/qemud.c | 1 +
src/Makefile.am | 8 ++-
src/nodeinfo.c | 55 +++----------------
src/remote_internal.c | 1 +
src/test.c | 2 -
tests/Makefile.am | 2 +
tests/nodeinfodata/linux-nodeinfo-1.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-2.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-3.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-4.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-5.txt | 2 +-
tests/nodeinfodata/linux-nodeinfo-6.txt | 2 +-
tests/nodeinfotest.c | 23 ++------
18 files changed, 131 insertions(+), 83 deletions(-)
create mode 100755 bootstrap
delete mode 100644 m4/Makefile.am
diff --git a/Makefile.am b/Makefile.am
index eaa204e..fcf0eb6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = src qemud proxy include docs @PYTHON_SUBDIR@ tests po m4 scripts
+SUBDIRS = lib src qemud proxy include docs @PYTHON_SUBDIR@ \
+ gl-tests tests po scripts
ACLOCAL_AMFLAGS = -I m4
diff --git a/bootstrap b/bootstrap
new file mode 100755
index 0000000..b49378d
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,90 @@
+#!/bin/sh
+# Run this after autogen.sh, to pull in all of the gnulib-related bits.
+# It's important to run *after* autogen.sh, since it updates some of
+# the same files autogen.sh does, yet those from gnulib are newer,
+# and match the tests. So if a gnulib bug has been fixed since the
+# snapshot taken for whatever gettext release you're using, yet you
+# run "make check" against the wrong version, the corresponding unit
+# test in gl-tests/ may well fail.
+
+usage() {
+ echo >&2 "\
+Usage: $0 [OPTION]...
+Bootstrap this package from the checked-out sources.
+
+Options:
+ --gnulib-srcdir=DIRNAME Specify the local directory where gnulib
+ sources reside. Use this if you already
+ have gnulib sources on your machine, and
+ do not want to waste your bandwidth downloading
+ them again.
+
+If the file bootstrap.conf exists in the current working directory, its
+contents are read as shell variables to configure the bootstrap.
+
+Running without arguments will suffice in most cases.
+"
+}
+
+for option
+do
+ case $option in
+ --help)
+ usage
+ exit;;
+ --gnulib-srcdir=*)
+ GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
+ *)
+ echo >&2 "$0: $option: unknown option"
+ exit 1;;
+ esac
+done
+
+case ${GNULIB_SRCDIR--} in
+-)
+ if [ ! -d gnulib ]; then
+ echo "$0: getting gnulib files..."
+
+ trap cleanup_gnulib 1 2 13 15
+
+ git clone --depth 1 git://git.sv.gnu.org/gnulib ||
+ cleanup_gnulib
+
+ trap - 1 2 13 15
+ fi
+ GNULIB_SRCDIR=gnulib
+esac
+
+gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
+<$gnulib_tool || exit
+
+# Tell gnulib to:
+# put tests in new gl-tests/ dir
+# put m4/*.m4 files in existing m4/ dir
+# lib/*.[ch] files in new lib/ dir.
+# With --avoid=snprintf, we pull in about 30 fewer files
+# With the current gnulib and gettext-0.17, the following
+# files are added to m4/ by both. But gnulib is stable enough
+# and gettext-0.16.1 is new enough that they are identical.
+# compiler-flags.m4
+# inttypes_h.m4
+# longlong.m4
+# size_max.m4
+# stdint_h.m4
+# wchar_t.m4
+# wint_t.m4
+# xsize.m4
+
+# Note that if we don't exclude the snprintf module, there are two tests
+# that have incompatible licenses, so we would have to exclude them. Even
+# excluding those two test modules, find reports a total of 94 added files.
+# Yes, snprintf has some heavy-duty dependents.
+# --avoid=snprintf-tests
+# --avoid=vasnprintf-tests
+
+$gnulib_tool \
+ --lgpl \
+ --avoid=snprintf \
+ --with-tests \
+ --tests-base=gl-tests \
+ --import physmem getaddrinfo
diff --git a/configure.in b/configure.in
index a845720..18a533f 100644
--- a/configure.in
+++ b/configure.in
@@ -28,11 +28,15 @@ AVAHI_REQUIRED="0.6.0"
dnl Checks for C compiler.
AC_PROG_CC
-AM_PROG_CC_STDC
-AC_C_CONST
AC_PROG_INSTALL
AC_PROG_CPP
+gl_EARLY
+gl_INIT
+
+AM_PROG_CC_STDC
+AC_C_CONST
+
dnl Make sure we have an ANSI compiler
AM_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)
@@ -562,11 +566,12 @@ cp COPYING.LIB COPYING
AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
docs/examples/Makefile docs/devhelp/Makefile \
docs/examples/python/Makefile \
+ lib/Makefile gl-tests/Makefile \
libvirt.pc libvirt.spec \
po/Makefile.in scripts/Makefile \
include/libvirt/Makefile include/libvirt/libvirt.h \
python/Makefile python/tests/Makefile \
- qemud/Makefile m4/Makefile \
+ qemud/Makefile \
tests/Makefile proxy/Makefile \
tests/xml2sexprdata/Makefile \
tests/sexpr2xmldata/Makefile \
diff --git a/m4/Makefile.am b/m4/Makefile.am
deleted file mode 100644
index 188b2fe..0000000
--- a/m4/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-
-EXTRA_DIST = compiler-flags.m4
-
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index 1737176..267b43e 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -27,6 +27,7 @@ libvirtd_SOURCES = \
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirtd_CFLAGS = \
+ -I$(top_srcdir)/lib -I../lib \
-I$(top_srcdir)/include -I$(top_builddir)/include \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) \
$(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
@@ -37,7 +38,7 @@ libvirtd_CFLAGS = \
libvirtd_LDFLAGS = $(WARN_CFLAGS) $(LIBXML_LIBS) $(GNUTLS_LIBS)
libvirtd_DEPENDENCIES = ../src/libvirt.la
-libvirtd_LDADD = ../src/libvirt.la
+libvirtd_LDADD = ../src/libvirt.la ../lib/libgnu.la
if HAVE_AVAHI
libvirtd_SOURCES += mdns.c mdns.h
diff --git a/qemud/qemud.c b/qemud/qemud.c
index f88ed42..caccd29 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -53,6 +53,7 @@
#include <libvirt/virterror.h>
#include "internal.h"
+#include "getaddrinfo.h"
#include "../src/internal.h"
#include "../src/remote_internal.h"
#include "../src/conf.h"
diff --git a/src/Makefile.am b/src/Makefile.am
index 52ffbaf..efea233 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,8 @@
## Process this file with automake to produce Makefile.in
-INCLUDES = -I$(top_builddir)/include \
+INCLUDES = \
+ -I$(top_srcdir)/lib -I../lib \
+ -I../include \
-I@top_srcdir@/include \
-I@top_srcdir@/qemud \
$(LIBXML_CFLAGS) \
@@ -14,7 +16,7 @@ INCLUDES = -I$(top_builddir)/include \
$(WARN_CFLAGS) \
$(LIBVIRT_FEATURES)
DEPS = libvirt.la
-LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la
+LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../lib/libgnu.la
VIRSH_LIBS = @VIRSH_LIBS@
confdir = $(sysconfdir)/libvirt/
@@ -60,7 +62,7 @@ SERVER_SOURCES = \
libvirt_la_SOURCES = $(CLIENT_SOURCES) $(SERVER_SOURCES)
libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(LTLIBOBJS) \
- @CYGWIN_EXTRA_LIBADD@
+ @CYGWIN_EXTRA_LIBADD@ ../lib/libgnu.la
libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \
-version-info @LIBVIRT_VERSION_INFO@ \
$(COVERAGE_CFLAGS:-f%=-Wc,-f%) \
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index a0a26eb..2ef49cb 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -29,14 +29,14 @@
#include <ctype.h>
#include "nodeinfo.h"
+#include "physmem.h"
#ifdef __linux__
-#define MEMINFO_PATH "/proc/meminfo"
#define CPUINFO_PATH "/proc/cpuinfo"
/* NB, these are not static as we need to call them from testsuite */
-int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo);
-int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo, virNodeInfoPtr nodeinfo);
+int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo,
+ virNodeInfoPtr nodeinfo);
int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo) {
char line[1024];
@@ -114,44 +114,11 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
return 0;
}
-
-int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo,
- virNodeInfoPtr nodeinfo) {
- char line[1024];
-
- nodeinfo->memory = 0;
-
- while (fgets(line, sizeof(line), meminfo) != NULL) {
- if (STREQLEN(line, "MemTotal:", 9)) {
- char *p;
- unsigned int ui;
- if (xstrtol_ui(line + 10, &p, 10, &ui) == 0
- && (*p == '\0' || isspace(*p))) {
- nodeinfo->memory = ui;
- break;
- }
- }
- }
- if (!nodeinfo->memory) {
- __virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "no memory found");
- return -1;
- }
-
- return 0;
-}
-
-
#endif
int virNodeInfoPopulate(virConnectPtr conn,
virNodeInfoPtr nodeinfo) {
struct utsname info;
-#ifdef __linux__
- int ret;
- FILE *cpuinfo, *meminfo;
-#endif
if (uname(&info) < 0) {
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
@@ -164,7 +131,9 @@ int virNodeInfoPopulate(virConnectPtr conn,
nodeinfo->model[sizeof(nodeinfo->model)-1] = '\0';
#ifdef __linux__
- cpuinfo = fopen(CPUINFO_PATH, "r");
+ {
+ int ret;
+ FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
@@ -176,17 +145,11 @@ int virNodeInfoPopulate(virConnectPtr conn,
if (ret < 0)
return -1;
- meminfo = fopen(MEMINFO_PATH, "r");
- if (!meminfo) {
- __virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
- VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "cannot open %s %s", MEMINFO_PATH, strerror(errno));
- return -1;
- }
- ret = linuxNodeInfoMemPopulate(conn, meminfo, nodeinfo);
- fclose(meminfo);
+ /* Convert to KB. */
+ nodeinfo->memory = physmem_total () / 1024;
return ret;
+ }
#else
/* XXX Solaris will need an impl later if they port QEMU driver */
__virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
diff --git a/src/remote_internal.c b/src/remote_internal.c
index a8227f3..275405a 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -52,6 +52,7 @@
#include "internal.h"
#include "driver.h"
+#include "getaddrinfo.h"
#include "remote_internal.h"
#include "remote_protocol.h"
diff --git a/src/test.c b/src/test.c
index 010ea15..bab280f 100644
--- a/src/test.c
+++ b/src/test.c
@@ -25,8 +25,6 @@
#ifdef WITH_TEST
-#define _GNU_SOURCE /* for asprintf */
-
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 512162b..4de0c45 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,6 +11,7 @@ SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata xencapsdat
LIBVIRT = $(wildcard $(top_builddir)/src/.libs/libvirt_la-*.o)
INCLUDES = \
+ -I$(top_srcdir)/lib -I../lib \
-I$(top_builddir)/include \
-I$(top_builddir)/src \
-I$(top_srcdir)/include \
@@ -29,6 +30,7 @@ LDADDS = \
$(GNUTLS_LIBS) \
$(WARN_CFLAGS) \
$(LIBVIRT) \
+ ../lib/libgnu.la \
$(COVERAGE_LDFLAGS)
EXTRA_DIST = \
diff --git a/tests/nodeinfodata/linux-nodeinfo-1.txt b/tests/nodeinfodata/linux-nodeinfo-1.txt
index 1a38ad1..e52e20a 100644
--- a/tests/nodeinfodata/linux-nodeinfo-1.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-1.txt
@@ -1 +1 @@
-CPUs: 2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Memory: 2053960
+CPUs: 2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-2.txt b/tests/nodeinfodata/linux-nodeinfo-2.txt
index 1c31a0c..12e819b 100644
--- a/tests/nodeinfodata/linux-nodeinfo-2.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-2.txt
@@ -1 +1 @@
-CPUs: 2, MHz: 2211, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Memory: 4059540
+CPUs: 2, MHz: 2211, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-3.txt b/tests/nodeinfodata/linux-nodeinfo-3.txt
index e2cc841..d285781 100644
--- a/tests/nodeinfodata/linux-nodeinfo-3.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-3.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1595, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1595, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-4.txt b/tests/nodeinfodata/linux-nodeinfo-4.txt
index 2c75ea3..991d4f9 100644
--- a/tests/nodeinfodata/linux-nodeinfo-4.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-4.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-5.txt b/tests/nodeinfodata/linux-nodeinfo-5.txt
index 01fee52..dce7ada 100644
--- a/tests/nodeinfodata/linux-nodeinfo-5.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-5.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 2814, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 2814, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfodata/linux-nodeinfo-6.txt b/tests/nodeinfodata/linux-nodeinfo-6.txt
index a7a2cfe..75cdaa9 100644
--- a/tests/nodeinfodata/linux-nodeinfo-6.txt
+++ b/tests/nodeinfodata/linux-nodeinfo-6.txt
@@ -1 +1 @@
-CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1, Memory: 4059272
+CPUs: 4, MHz: 1000, Nodes: 1, Sockets: 2, Cores: 2, Threads: 1
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 7275cc3..fb563b5 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -21,14 +21,13 @@ static char *abs_top_srcdir;
#ifdef __linux__
extern int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo);
-extern int linuxNodeInfoMemPopulate(virConnectPtr conn, FILE *meminfo, virNodeInfoPtr nodeinfo);
-static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofile, const char *outputfile) {
+static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) {
char actualData[MAX_FILE];
char expectData[MAX_FILE];
char *expect = &expectData[0];
virNodeInfo nodeinfo;
- FILE *cpuinfo, *meminfo;
+ FILE *cpuinfo;
if (virtTestLoadFile(outputfile, &expect, MAX_FILE) < 0)
return -1;
@@ -42,19 +41,10 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofil
}
fclose(cpuinfo);
- meminfo = fopen(meminfofile, "r");
- if (!meminfo)
- return -1;
- if (linuxNodeInfoMemPopulate(NULL, meminfo, &nodeinfo) < 0) {
- fclose(meminfo);
- return -1;
- }
- fclose(meminfo);
-
snprintf(actualData, MAX_FILE,
- "CPUs: %u, MHz: %u, Nodes: %u, Sockets: %u, Cores: %u, Threads: %u, Memory: %lu\n",
+ "CPUs: %u, MHz: %u, Nodes: %u, Sockets: %u, Cores: %u, Threads: %u\n",
nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets,
- nodeinfo.cores, nodeinfo.threads, nodeinfo.memory);
+ nodeinfo.cores, nodeinfo.threads);
if (STRNEQ(actualData, expectData)) {
if (getenv("DEBUG_TESTS")) {
@@ -70,15 +60,12 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *meminfofil
static int linuxTestNodeInfo(const void *data) {
char cpuinfo[PATH_MAX];
- char meminfo[PATH_MAX];
char output[PATH_MAX];
snprintf(cpuinfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.cpuinfo",
abs_top_srcdir, (const char*)data);
- snprintf(meminfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.meminfo",
- abs_top_srcdir, (const char*)data);
snprintf(output, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.txt",
abs_top_srcdir, (const char*)data);
- return linuxTestCompareFiles(cpuinfo, meminfo, output);
+ return linuxTestCompareFiles(cpuinfo, output);
}
#endif
--
1.5.3.6.950.g92b7b
16 years, 11 months