# Initialize Automake
AM_INIT_AUTOMAKE([foreign dist-bzip2])
AM_MAINTAINER_MODE
+AC_USE_SYSTEM_EXTENSIONS
# Initialize libtool
AC_PROG_LIBTOOL
#define DO_MATCH(a,b) (((a) == PCI_MATCH_ANY) || ((a) == (b)))
#ifdef HAVE_ZLIB
+
#include <zlib.h>
typedef gzFile pci_id_file;
#define pci_id_file_gets(l, s, f) gzgets(f, l, s)
#define pci_id_file_close(f) gzclose(f)
-#else
+
+#else /* not zlib */
+
typedef FILE * pci_id_file;
-#define pci_id_file_open() fopen(PCIIDS_PATH "/pci.ids", "r")
+
+static pci_id_file
+pci_id_file_open(void)
+{
+ pci_id_file result;
+
+#ifndef __sun
+ result = fopen(PCIIDS_PATH "/pci.ids", "re");
+ if (result)
+ return result;
+#endif
+
+ return fopen(PCIIDS_PATH "/pci.ids", "r");
+}
+
#define pci_id_file_gets(l, s, f) fgets(l, s, f)
#define pci_id_file_close(f) fclose(f)
+
#endif
/**
if (!pci_sys)
return -1;
- if ((pci_sys->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR)) < 0) {
+ if ((pci_sys->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR | O_CLOEXEC)) < 0) {
return errno;
}
int fd, err = 0;
- fd = open("/dev/mem", O_RDWR);
+ fd = open("/dev/mem", O_RDWR | O_CLOEXEC);
if (fd == -1)
return errno;
if ((map->flags & PCI_DEV_MAP_FLAG_CACHABLE) ||
(map->flags & PCI_DEV_MAP_FLAG_WRITE_COMBINE))
{
- fd = open("/dev/mem", O_RDWR);
+ fd = open("/dev/mem", O_RDWR | O_CLOEXEC);
if (fd != -1) {
mrd.mr_base = map->base;
mrd.mr_len = map->size;
}
printf("Using rom_base = 0x%lx\n", (long)rom_base);
- memfd = open( "/dev/mem", O_RDONLY );
+ memfd = open( "/dev/mem", O_RDONLY | O_CLOEXEC );
if ( memfd == -1 )
return errno;
int i;
/* Try to open the PCI device */
- pcidev = open( "/dev/pci", O_RDWR );
+ pcidev = open( "/dev/pci", O_RDWR | O_CLOEXEC );
if ( pcidev == -1 )
return ENXIO;
if ( pci_sys != NULL ) {
pci_sys->methods = & linux_sysfs_methods;
#ifdef HAVE_MTRR
- pci_sys->mtrr_fd = open("/proc/mtrr", O_WRONLY);
+ pci_sys->mtrr_fd = open("/proc/mtrr", O_WRONLY | O_CLOEXEC);
#endif
err = populate_entries(pci_sys);
}
dev->bus,
dev->dev,
dev->func );
- fd = open( name, O_RDONLY );
+ fd = open( name, O_RDONLY | O_CLOEXEC);
if ( fd != -1 ) {
char * next;
pciaddr_t low_addr;
dev->dev,
dev->func );
- fd = open( name, O_RDWR );
+ fd = open( name, O_RDWR | O_CLOEXEC);
if ( fd == -1 ) {
#ifdef LINUX_ROM
/* If reading the ROM using sysfs fails, fall back to the old
dev->dev,
dev->func );
- fd = open( name, O_RDONLY );
+ fd = open( name, O_RDONLY | O_CLOEXEC);
if ( fd == -1 ) {
return errno;
}
dev->dev,
dev->func );
- fd = open( name, O_WRONLY );
+ fd = open( name, O_WRONLY | O_CLOEXEC);
if ( fd == -1 ) {
return errno;
}
dev->dev,
dev->func,
map->region);
- fd = open(name, open_flags);
+ fd = open(name, open_flags | O_CLOEXEC);
if (fd == -1)
return errno;
dev->func,
map->region);
- fd = open(name, open_flags);
+ fd = open(name, open_flags | O_CLOEXEC);
if (fd == -1) {
return errno;
}
dev->dev,
dev->func );
- fd = open( name, O_RDWR );
+ fd = open( name, O_RDWR | O_CLOEXEC);
if (fd == -1)
return;
dev->dev,
dev->func );
- fd = open( name, O_RDONLY );
+ fd = open( name, O_RDONLY | O_CLOEXEC);
if (fd == -1)
return 0;
snprintf(name, PATH_MAX, "%s/%04x:%02x:%02x.%1u/resource%d",
SYS_BUS_PCI, dev->domain, dev->bus, dev->dev, dev->func, bar);
- ret->fd = open(name, O_RDWR);
+ ret->fd = open(name, O_RDWR | O_CLOEXEC);
if (ret->fd < 0)
return NULL;
snprintf(name, PATH_MAX, "/sys/class/pci_bus/%04x:%02x/legacy_io",
dev->domain, dev->bus);
- ret->fd = open(name, O_RDWR);
+ ret->fd = open(name, O_RDWR | O_CLOEXEC);
if (ret->fd >= 0)
break;
snprintf(name, PATH_MAX, "/sys/class/pci_bus/%04x:%02x/legacy_mem",
dev->domain, dev->bus);
- fd = open(name, flags);
+ fd = open(name, flags | O_CLOEXEC);
if (fd >= 0)
break;
/* If not, /dev/mem is the best we can do */
if (!dev)
- fd = open("/dev/mem", flags);
+ fd = open("/dev/mem", flags | O_CLOEXEC);
if (fd < 0)
return errno;
struct mtrr mtrr;
int fd, error, nmtrr, prot = PROT_READ;
- if ((fd = open("/dev/mem", O_RDWR)) == -1)
+ if ((fd = open("/dev/mem", O_RDWR | O_CLOEXEC)) == -1)
return errno;
if (map->flags & PCI_DEV_MAP_FLAG_WRITABLE)
int bus, dev, func, ndevs, nfuncs;
uint32_t reg;
- pcifd = open("/dev/pci0", O_RDWR);
+ pcifd = open("/dev/pci0", O_RDWR | O_CLOEXEC);
if (pcifd == -1)
return ENXIO;
for (domain = 0; domain < sizeof(pcifd) / sizeof(pcifd[0]); domain++) {
snprintf(path, sizeof(path), "/dev/pci%d", domain);
- pcifd[domain] = open(path, O_RDWR);
+ pcifd[domain] = open(path, O_RDWR | O_CLOEXEC);
if (pcifd[domain] == -1)
break;
ndomains++;
# define _pci_hidden
#endif /* GNUC >= 4 */
+/*
+ * O_CLOEXEC fixes an fd leak case (see 'man 2 open' for details). I don't
+ * know of any OS we support where this isn't available in a sufficiently
+ * new version, so warn unconditionally.
+ */
+#include <sys/fcntl.h>
+
+#ifndef O_CLOEXEC
+#warning O_CLOEXEC not available, please upgrade.
+#define O_CLOEXEC 0
+#endif
+
+
struct pci_device_mapping;
int pci_fill_capabilities_generic( struct pci_device * dev );
nexus_path, first_bus, last_bus);
#endif
- if ((fd = open(nexus_path, O_RDWR)) >= 0) {
+ if ((fd = open(nexus_path, O_RDWR | O_CLOEXEC)) >= 0) {
nexus->fd = fd;
nexus->path = strdup(nexus_path);
nexus_dev_path = di_devfs_path(di_node);
else
strcpy (map_dev, "/dev/fb0");
- if ((map_fd = open(map_dev, O_RDWR)) < 0) {
+ if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) {
err = errno;
(void) fprintf(stderr, "can not open %s: %s\n", map_dev,
strerror(errno));
* Still used xsvc to do the user space mapping
*/
if (xsvc_fd < 0) {
- if ((xsvc_fd = open("/dev/xsvc", O_RDWR)) < 0) {
+ if ((xsvc_fd = open("/dev/xsvc", O_RDWR | O_CLOEXEC)) < 0) {
err = errno;
(void) fprintf(stderr, "can not open /dev/xsvc: %s\n",
strerror(errno));
return ENOSYS;
}
- memfd = open("/dev/mem", O_RDONLY);
+ memfd = open("/dev/mem", O_RDONLY | O_CLOEXEC);
if (memfd == -1)
return errno;
pci_device_x86_map_range(struct pci_device *dev,
struct pci_device_mapping *map)
{
- int memfd = open("/dev/mem", O_RDWR);
+ int memfd = open("/dev/mem", O_RDWR | O_CLOEXEC);
int prot = PROT_READ;
if (memfd == -1)