[libvirt] [PATCH] Only initialize/cleanup libpciaccess once

Daniel P. Berrange berrange at redhat.com
Mon Feb 7 17:05:58 UTC 2011


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 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 379af86..2da5529 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();
-- 
1.7.4




More information about the libvir-list mailing list