]> xenbits.xensource.com Git - libvirt.git/commitdiff
Only initialize/cleanup libpciaccess once
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 7 Feb 2011 17:04:35 +0000 (17:04 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 9 Feb 2011 16:20:27 +0000 (16:20 +0000)
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

index 379af86f56a9062f68c606fa121f104a99acd1ef..2da552987d0aacf929e9ee679d831667da4d4d3e 100644 (file)
@@ -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();