[PATCH 4/7] tests: cgroupmock: Use the temporary directory as fake root

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 tests/vircgroupmock.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index f2fee7d..ead18b6 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -31,6 +31,8 @@
 # include <sys/stat.h>
 # include <stdarg.h>
 # include "testutilslxc.h"
+# include "virstring.h"
+# include "virfile.h"
 
 static int (*realopen)(const char *path, int flags, ...);
 static FILE *(*realfopen)(const char *path, const char *mode);
@@ -45,6 +47,7 @@ static int (*realmkdir)(const char *path, mode_t mode);
  * 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]
  */
+char *fakerootdir;
 char *fakesysfsdir;
 const char *fakedevicedir0 = FAKEDEVDIR0;
 const char *fakedevicedir1 = FAKEDEVDIR1;
@@ -414,14 +417,23 @@ static void init_syms(void)
 
 static void init_sysfs(void)
 {
-    if (fakesysfsdir)
+    if (fakerootdir && fakesysfsdir)
         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");
         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)                               \
     do {                                                        \
         char *path;                                             \
-- 
2.5.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]