mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-06 09:55:46 +00:00
nssmock: Adapt to virmock.h
Instead of introducing our own wrapper for dlsym() we can use the one provided by virmock.h. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
d16b7a8853
commit
ca88c0e7b2
@ -21,55 +21,32 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef NSS
|
#ifdef NSS
|
||||||
# include <stdio.h>
|
# include "virmock.h"
|
||||||
# include <stdlib.h>
|
|
||||||
# include <dlfcn.h>
|
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
|
||||||
# include "configmake.h"
|
# include "configmake.h"
|
||||||
# include "internal.h"
|
|
||||||
# include "virstring.h"
|
# include "virstring.h"
|
||||||
# include "viralloc.h"
|
# include "viralloc.h"
|
||||||
|
|
||||||
static int (*realopen)(const char *path, int flags, ...);
|
static int (*real_open)(const char *path, int flags, ...);
|
||||||
static DIR * (*realopendir)(const char *name);
|
static DIR * (*real_opendir)(const char *name);
|
||||||
|
|
||||||
# define LEASEDIR LOCALSTATEDIR "/lib/libvirt/dnsmasq/"
|
# define LEASEDIR LOCALSTATEDIR "/lib/libvirt/dnsmasq/"
|
||||||
|
|
||||||
# define STDERR(...) \
|
|
||||||
fprintf(stderr, "%s %zu: ", __FUNCTION__, (size_t) __LINE__); \
|
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
|
||||||
fprintf(stderr, "\n"); \
|
|
||||||
|
|
||||||
# define ABORT(...) \
|
|
||||||
do { \
|
|
||||||
STDERR(__VA_ARGS__); \
|
|
||||||
abort(); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
# define ABORT_OOM() \
|
|
||||||
ABORT("Out of memory")
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions to load the symbols and init the environment
|
* Functions to load the symbols and init the environment
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
init_syms(void)
|
init_syms(void)
|
||||||
{
|
{
|
||||||
if (realopen)
|
if (real_open)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# define LOAD_SYM(name) \
|
VIR_MOCK_REAL_INIT(open);
|
||||||
do { \
|
VIR_MOCK_REAL_INIT(opendir);
|
||||||
if (!(real ## name = dlsym(RTLD_NEXT, #name))) \
|
|
||||||
ABORT("Cannot find real '%s' symbol\n", #name); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
LOAD_SYM(open);
|
|
||||||
LOAD_SYM(opendir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -109,9 +86,9 @@ open(const char *path, int flags, ...)
|
|||||||
va_start(ap, flags);
|
va_start(ap, flags);
|
||||||
mode = va_arg(ap, int);
|
mode = va_arg(ap, int);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
ret = realopen(newpath ? newpath : path, flags, mode);
|
ret = real_open(newpath ? newpath : path, flags, mode);
|
||||||
} else {
|
} else {
|
||||||
ret = realopen(newpath ? newpath : path, flags);
|
ret = real_open(newpath ? newpath : path, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(newpath);
|
VIR_FREE(newpath);
|
||||||
@ -130,7 +107,7 @@ opendir(const char *path)
|
|||||||
getrealpath(&newpath, path) < 0)
|
getrealpath(&newpath, path) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = realopendir(newpath ? newpath : path);
|
ret = real_opendir(newpath ? newpath : path);
|
||||||
|
|
||||||
VIR_FREE(newpath);
|
VIR_FREE(newpath);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user