mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virpcimock: Eliminate use of @fakesysfspcidir
The @fakesysfspcidir is derived from @fakerootdir. We don't need two global variables that contain nearly the same content, especially when we construct the actual path anyways. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
ea893afaf8
commit
2a0909484b
@ -42,7 +42,6 @@ static char *(*real_virFileCanonicalizePath)(const char *path);
|
|||||||
* 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 *fakerootdir;
|
||||||
char *fakesysfspcidir;
|
|
||||||
|
|
||||||
# define SYSFS_PCI_PREFIX "/sys/bus/pci/"
|
# define SYSFS_PCI_PREFIX "/sys/bus/pci/"
|
||||||
|
|
||||||
@ -213,9 +212,7 @@ pci_read_file(const char *path,
|
|||||||
int fd = -1;
|
int fd = -1;
|
||||||
VIR_AUTOFREE(char *) newpath = NULL;
|
VIR_AUTOFREE(char *) newpath = NULL;
|
||||||
|
|
||||||
if (virAsprintfQuiet(&newpath, "%s/%s",
|
if (virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path) < 0) {
|
||||||
fakesysfspcidir,
|
|
||||||
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
|
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -246,8 +243,8 @@ getrealpath(char **newpath,
|
|||||||
init_env();
|
init_env();
|
||||||
|
|
||||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
|
||||||
if (virAsprintfQuiet(newpath, "%s/%s",
|
if (virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s",
|
||||||
fakesysfspcidir,
|
fakerootdir,
|
||||||
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
|
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
@ -357,7 +354,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
|
|||||||
if (VIR_ALLOC_QUIET(dev) < 0 ||
|
if (VIR_ALLOC_QUIET(dev) < 0 ||
|
||||||
virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
|
virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
|
||||||
abs_srcdir, id) < 0 ||
|
abs_srcdir, id) < 0 ||
|
||||||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfspcidir, data->id) < 0)
|
virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", fakerootdir, data->id) < 0)
|
||||||
ABORT_OOM();
|
ABORT_OOM();
|
||||||
|
|
||||||
memcpy(dev, data, sizeof(*dev));
|
memcpy(dev, data, sizeof(*dev));
|
||||||
@ -479,7 +476,7 @@ pci_driver_new(const char *name, int fail, ...)
|
|||||||
|
|
||||||
if (VIR_ALLOC_QUIET(driver) < 0 ||
|
if (VIR_ALLOC_QUIET(driver) < 0 ||
|
||||||
VIR_STRDUP_QUIET(driver->name, name) < 0 ||
|
VIR_STRDUP_QUIET(driver->name, name) < 0 ||
|
||||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfspcidir, name) < 0)
|
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakerootdir, name) < 0)
|
||||||
ABORT_OOM();
|
ABORT_OOM();
|
||||||
|
|
||||||
driver->fail = fail;
|
driver->fail = fail;
|
||||||
@ -586,10 +583,10 @@ pci_driver_bind(struct pciDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make symlink under device tree */
|
/* Make symlink under device tree */
|
||||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
|
if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver",
|
||||||
fakesysfspcidir, dev->id) < 0 ||
|
fakerootdir, dev->id) < 0 ||
|
||||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s",
|
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s",
|
||||||
fakesysfspcidir, driver->name) < 0) {
|
fakerootdir, driver->name) < 0) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -600,10 +597,10 @@ pci_driver_bind(struct pciDriver *driver,
|
|||||||
/* Make symlink under driver tree */
|
/* Make symlink under driver tree */
|
||||||
VIR_FREE(devpath);
|
VIR_FREE(devpath);
|
||||||
VIR_FREE(driverpath);
|
VIR_FREE(driverpath);
|
||||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s",
|
if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s",
|
||||||
fakesysfspcidir, dev->id) < 0 ||
|
fakerootdir, dev->id) < 0 ||
|
||||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
|
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s",
|
||||||
fakesysfspcidir, driver->name, dev->id) < 0) {
|
fakerootdir, driver->name, dev->id) < 0) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -629,10 +626,10 @@ pci_driver_unbind(struct pciDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make symlink under device tree */
|
/* Make symlink under device tree */
|
||||||
if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
|
if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver",
|
||||||
fakesysfspcidir, dev->id) < 0 ||
|
fakerootdir, dev->id) < 0 ||
|
||||||
virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
|
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s",
|
||||||
fakesysfspcidir, driver->name, dev->id) < 0) {
|
fakerootdir, driver->name, dev->id) < 0) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -836,7 +833,9 @@ init_syms(void)
|
|||||||
static void
|
static void
|
||||||
init_env(void)
|
init_env(void)
|
||||||
{
|
{
|
||||||
if (fakerootdir && fakesysfspcidir)
|
VIR_AUTOFREE(char *) fakesysfspcidir = NULL;
|
||||||
|
|
||||||
|
if (fakerootdir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))
|
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))
|
||||||
|
Loading…
Reference in New Issue
Block a user