daemon: Autodetect lock driver directory

When running libvirtd from a build directory, libvirtd would load lock
drivers from system directory unless explicitly overridden by setting
LIBVIRT_LOCK_MANAGER_PLUGIN_DIR environment variable. Since we already
autodetect driver directory if libvirt is build with driver modules, we
can use the same trick to automagically set lock driver directory.
This commit is contained in:
Jiri Denemark 2012-08-21 15:21:47 +02:00
parent 1a4379cb21
commit 15f5e16f4e
4 changed files with 17 additions and 3 deletions

View File

@ -55,6 +55,7 @@
#include "hooks.h"
#include "uuid.h"
#include "viraudit.h"
#include "locking/lock_manager.h"
#ifdef WITH_DRIVER_MODULES
# include "driver.h"
@ -971,7 +972,6 @@ int main(int argc, char **argv) {
/* initialize early logging */
virLogSetFromEnv();
#ifdef WITH_DRIVER_MODULES
if (strstr(argv[0], "lt-libvirtd") ||
strstr(argv[0], "/daemon/.libs/libvirtd")) {
char *tmp = strrchr(argv[0], '/');
@ -990,11 +990,13 @@ int main(int argc, char **argv) {
argv[0], driverdir);
exit(EXIT_FAILURE);
}
virLockManagerSetPluginDir(driverdir);
#ifdef WITH_DRIVER_MODULES
virDriverModuleInitialize(driverdir);
#endif
*tmp = '/';
/* Must not free 'driverdir' - it is still used */
}
#endif
while (1) {
int optidx = 0;

View File

@ -757,6 +757,7 @@ virLockManagerPluginUnref;
virLockManagerPluginUsesState;
virLockManagerPluginGetName;
virLockManagerRelease;
virLockManagerSetPluginDir;
# logging.h

View File

@ -64,6 +64,16 @@ struct _virLockManagerPlugin {
#define DEFAULT_LOCK_MANAGER_PLUGIN_DIR LIBDIR "/libvirt/lock-driver"
static const char *virLockManagerPluginDir = DEFAULT_LOCK_MANAGER_PLUGIN_DIR;
void
virLockManagerSetPluginDir(const char *dir)
{
if (dir)
virLockManagerPluginDir = dir;
}
static void virLockManagerLogParams(size_t nparams,
virLockManagerParamPtr params)
{
@ -128,7 +138,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
driver = &virLockDriverNop;
} else {
if (moddir == NULL)
moddir = DEFAULT_LOCK_MANAGER_PLUGIN_DIR;
moddir = virLockManagerPluginDir;
VIR_DEBUG("Module load %s from %s", name, moddir);

View File

@ -28,6 +28,7 @@
typedef struct _virLockManagerPlugin virLockManagerPlugin;
typedef virLockManagerPlugin *virLockManagerPluginPtr;
void virLockManagerSetPluginDir(const char *dir);
virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
const char *configFile,
unsigned int flags);