From 2215050edd8adefbf0ff21c5cbf09685877492d6 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 7 Feb 2011 17:04:35 +0000 Subject: [PATCH] Only initialize/cleanup libpciaccess once libpciaccess has many bugs in its pci_system_init/cleanup functions that makes calling them multiple times unwise. eg it will double close() FDs, and leak other FDs. * src/node_device/node_device_udev.c: Only initialize libpciaccess once --- src/node_device/node_device_udev.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 379af86f56..2da552987d 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -363,18 +363,10 @@ static int udevTranslatePCIIds(unsigned int vendor, char **vendor_string, char **product_string) { - int ret = -1, pciret; + int ret = -1; struct pci_id_match m; const char *vendor_name = NULL, *device_name = NULL; - if ((pciret = pci_system_init()) != 0) { - char ebuf[256]; - VIR_INFO("Failed to initialize libpciaccess: %s", - virStrerror(pciret, ebuf, sizeof ebuf)); - ret = 0; - goto out; - } - m.vendor_id = vendor; m.device_id = product; m.subvendor_id = PCI_MATCH_ANY; @@ -406,9 +398,6 @@ static int udevTranslatePCIIds(unsigned int vendor, } } - /* pci_system_cleanup returns void */ - pci_system_cleanup(); - ret = 0; out: @@ -1426,6 +1415,9 @@ static int udevDeviceMonitorShutdown(void) ret = -1; } + /* pci_system_cleanup returns void */ + pci_system_cleanup(); + return ret; } @@ -1593,6 +1585,15 @@ static int udevDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED) udevPrivate *priv = NULL; struct udev *udev = NULL; int ret = 0; + int pciret; + + if ((pciret = pci_system_init()) != 0) { + char ebuf[256]; + VIR_INFO("Failed to initialize libpciaccess: %s", + virStrerror(pciret, ebuf, sizeof ebuf)); + ret = -1; + goto out; + } if (VIR_ALLOC(priv) < 0) { virReportOOMError(); -- 2.39.5