提交 bc80c45d 编写于 作者: A Andrea Bolognani

tests: cgroupmock: Use the temporary directory as fake root

We might need to mock files living outside SYSFS_PREFIX later on,
so it's better to treat the temporary directory we are passed via
the environment as the root of the fake filesystem and create
SYSFS_PREFIX inside it.

The environment variable name will be changed to reflect the new use
we're making of it in a later commit.
上级 f94398e7
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
# include <sys/stat.h> # include <sys/stat.h>
# include <stdarg.h> # include <stdarg.h>
# include "testutilslxc.h" # include "testutilslxc.h"
# include "virstring.h"
# include "virfile.h"
static int (*realopen)(const char *path, int flags, ...); static int (*realopen)(const char *path, int flags, ...);
static FILE *(*realfopen)(const char *path, const char *mode); static FILE *(*realfopen)(const char *path, const char *mode);
...@@ -45,6 +47,7 @@ static int (*realmkdir)(const char *path, mode_t mode); ...@@ -45,6 +47,7 @@ static int (*realmkdir)(const char *path, mode_t mode);
* when passed as an arg to asprintf() * when passed as an arg to asprintf()
* vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline] * vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
*/ */
char *fakerootdir;
char *fakesysfsdir; char *fakesysfsdir;
const char *fakedevicedir0 = FAKEDEVDIR0; const char *fakedevicedir0 = FAKEDEVDIR0;
const char *fakedevicedir1 = FAKEDEVDIR1; const char *fakedevicedir1 = FAKEDEVDIR1;
...@@ -414,14 +417,23 @@ static void init_syms(void) ...@@ -414,14 +417,23 @@ static void init_syms(void)
static void init_sysfs(void) static void init_sysfs(void)
{ {
if (fakesysfsdir) if (fakerootdir && fakesysfsdir)
return; return;
if (!(fakesysfsdir = getenv("LIBVIRT_FAKE_SYSFS_DIR"))) { if (!(fakerootdir = getenv("LIBVIRT_FAKE_SYSFS_DIR"))) {
fprintf(stderr, "Missing LIBVIRT_FAKE_SYSFS_DIR env variable\n"); fprintf(stderr, "Missing LIBVIRT_FAKE_SYSFS_DIR env variable\n");
abort(); abort();
} }
if (virAsprintfQuiet(&fakesysfsdir, "%s%s",
fakerootdir, SYSFS_PREFIX) < 0)
abort();
if (virFileMakePath(fakesysfsdir) < 0) {
fprintf(stderr, "Cannot create %s\n", fakesysfsdir);
abort();
}
# define MAKE_CONTROLLER(subpath) \ # define MAKE_CONTROLLER(subpath) \
do { \ do { \
char *path; \ char *path; \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册