OpenBSD: allow 2 successives calls to pci_system_init().
authorMatthieu Herrb <matthieu.herrb@laas.fr>
Sat, 20 Sep 2008 16:28:59 +0000 (18:28 +0200)
committerMatthieu Herrb <matthieu.herrb@laas.fr>
Sat, 20 Sep 2008 16:28:59 +0000 (18:28 +0200)
And fix pci_system_cleanup() to make it possible to call pci_system_init()
again.
ok kettenis at openbsd.

src/openbsd_pci.c

index 5c06b47..7bb20d6 100644 (file)
@@ -33,7 +33,7 @@
 #include "pciaccess.h"
 #include "pciaccess_private.h"
 
-static int pcifd;
+static int pcifd = -1;
 static int aperturefd = -1;
 
 static int
@@ -216,6 +216,8 @@ pci_system_openbsd_destroy(void)
 {
        close(aperturefd);
        close(pcifd);
+       aperturefd = -1;
+       pcifd = -1;
        free(pci_sys);
        pci_sys = NULL;
 }
@@ -318,6 +320,9 @@ pci_system_openbsd_create(void)
        int bus, dev, func, ndevs, nfuncs;
        uint32_t reg;
 
+       if (pcifd != -1) 
+               return 0;
+
        pcifd = open("/dev/pci", O_RDWR);
        if (pcifd == -1)
                return ENXIO;