Load CPU map from builddir when run uninstalled

When libvirtd is run from a build directory without being installed, it
should not depend on files from a libvirt package installed in the
system. Not only because there may not be any libvirt installed at all.
We already do a good job for plugins but cpu_map.xml was still loaded
from the system.

The Makefile.am change is necessary to make this all work from VPATH
builds since libvirtd has no idea where to find libvirt sources. It only
knows the path from which it was started, i.e, a builddir.

https://bugzilla.redhat.com/show_bug.cgi?id=1074327
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2014-03-10 16:00:49 +01:00
parent 7b91dc3ecd
commit e562e82f76
3 changed files with 13 additions and 1 deletions

View File

@ -103,6 +103,7 @@
#include "configmake.h"
#include "virdbus.h"
#include "cpu/cpu_map.h"
#if WITH_SASL
virNetSASLContextPtr saslCtxt = NULL;
@ -1157,13 +1158,16 @@ int main(int argc, char **argv) {
if (strstr(argv[0], "lt-libvirtd") ||
strstr(argv[0], "/daemon/.libs/libvirtd")) {
char *tmp = strrchr(argv[0], '/');
char *cpumap;
if (!tmp) {
fprintf(stderr, _("%s: cannot identify driver directory\n"), argv[0]);
exit(EXIT_FAILURE);
}
*tmp = '\0';
char *driverdir;
if (virAsprintfQuiet(&driverdir, "%s/../../src/.libs", argv[0]) < 0) {
if (virAsprintfQuiet(&driverdir, "%s/../../src/.libs", argv[0]) < 0 ||
virAsprintfQuiet(&cpumap, "%s/../../src/cpu/cpu_map.xml",
argv[0]) < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
}
@ -1176,6 +1180,7 @@ int main(int argc, char **argv) {
#ifdef WITH_DRIVER_MODULES
virDriverModuleInitialize(driverdir);
#endif
cpuMapOverride(cpumap);
*tmp = '/';
/* Must not free 'driverdir' - it is still used */
}

View File

@ -976,6 +976,10 @@ libvirt_la_BUILT_LIBADD += libvirt_cpu.la
libvirt_cpu_la_CFLAGS = \
-I$(top_srcdir)/src/conf $(AM_CFLAGS)
libvirt_cpu_la_SOURCES = $(CPU_SOURCES)
libvirt_cpu_la_DEPENDENCIES = $(abs_builddir)/cpu/cpu_map.xml
$(abs_builddir)/cpu/cpu_map.xml:
$(AM_V_GEN)ln -s $(abs_srcdir)/cpu/cpu_map.xml $@
if WITH_VMX
noinst_LTLIBRARIES += libvirt_vmx.la

View File

@ -28,6 +28,7 @@
#include "cpu_map.h"
#include "configmake.h"
#include "virstring.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_CPU
@ -86,6 +87,8 @@ int cpuMapLoad(const char *arch,
int element;
const char *mapfile = (cpumap ? cpumap : CPUMAPFILE);
VIR_DEBUG("Loading CPU map from %s", mapfile);
if (arch == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("undefined hardware architecture"));