static char *(*real_virFileCanonicalizePath)(const char *path);
static char *fakerootdir;
+static bool fakerootClean;
/* To add a new mocked prefix in virpcimock:
* - add the prefix here as a define to make it easier to track what we
.vpd_len = G_N_ELEMENTS(fullVPDExampleData),
};
- if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))
- ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n");
+ if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR"))) {
+ GError *err = NULL;
+
+ fakerootdir = g_dir_make_tmp(NULL, &err);
+ if (err != NULL) {
+ ABORT("Unable to create a temporary dir: %s\n", err->message);
+ }
+
+ fakerootClean = true;
+ }
tmp = g_strdup_printf("%s%s", fakerootdir, SYSFS_PCI_PREFIX);
}
+static void __attribute__((destructor))
+deinit_env(void)
+{
+ if (!fakerootClean)
+ return;
+
+ virFileDeleteTree(fakerootdir);
+ g_clear_pointer(&fakerootdir, g_free);
+ fakerootClean = false;
+}
+
+
/*
*
* Mocked functions