ocloexec
authorAnas Nashif <anas.nashif@intel.com>
Tue, 6 Nov 2012 17:12:35 +0000 (09:12 -0800)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Tue, 21 Jan 2014 08:52:22 +0000 (09:52 +0100)
lib/dump.c
lib/names-cache.c
lib/names-parse.c
lib/proc.c
lib/sysfs.c

index 59cf7ed432d82db7d0ccb8ceded76538533f186c..5c06b2aa8671c721930b5bddec9aba4cf53ff1af 100644 (file)
@@ -64,7 +64,7 @@ dump_init(struct pci_access *a)
 
   if (!name)
     a->error("dump: File name not given.");
-  if (!(f = fopen(name, "r")))
+  if (!(f = fopen(name, "re")))
     a->error("dump: Cannot open %s: %s", name, strerror(errno));
   while (fgets(buf, sizeof(buf)-1, f))
     {
index 90a6454a2c91781d9b331b82e165a0e5d9bc00b3..ffc7241a481cd10403fbad8c87574911eb64c23d 100644 (file)
@@ -62,7 +62,7 @@ pci_id_cache_load(struct pci_access *a, int flags)
       return 0;
     }
 
-  f = fopen(name, "rb");
+  f = fopen(name, "rbe");
   if (!f)
     {
       a->debug("Cache file does not exist\n");
@@ -135,7 +135,7 @@ pci_id_cache_flush(struct pci_access *a)
   tmpname = pci_malloc(a, strlen(name) + strlen(hostname) + 64);
   sprintf(tmpname, "%s.tmp-%s-%d", name, hostname, this_pid);
 
-  f = fopen(tmpname, "wb");
+  f = fopen(tmpname, "wbe");
   if (!f)
     {
       a->warning("Cannot write to %s: %s", name, strerror(errno));
index 4997b58bf6c44ab28e24ba61bb6c962cc9632d52..9d979ad5ed39539e79ed938b1346263a60bc9a69 100644 (file)
@@ -52,7 +52,7 @@ static pci_file pci_open(struct pci_access *a)
 typedef FILE * pci_file;
 #define pci_gets(f, l, s)      fgets(l, s, f)
 #define pci_eof(f)             feof(f)
-#define pci_open(a)            fopen(a->id_file_name, "r")
+#define pci_open(a)            fopen(a->id_file_name, "re")
 #define pci_close(f)           fclose(f)
 #define PCI_ERROR(f, err)      if (!err && ferror(f))  err = "I/O error";
 #endif
index cb9d08d17768dd1379849ca505d58ebe33067fae..7900fb96f0721297f7548c74734f76f922d407f0 100644 (file)
@@ -62,7 +62,7 @@ proc_scan(struct pci_access *a)
 
   if (snprintf(buf, sizeof(buf), "%s/devices", pci_get_param(a, "proc.path")) == sizeof(buf))
     a->error("File name too long");
-  f = fopen(buf, "r");
+  f = fopen(buf, "re");
   if (!f)
     a->error("Cannot open %s", buf);
   while (fgets(buf, sizeof(buf)-1, f))
@@ -129,7 +129,7 @@ proc_setup(struct pci_dev *d, int rw)
       if (e < 0 || e >= (int) sizeof(buf))
        a->error("File name too long");
       a->fd_rw = a->writeable || rw;
-      a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY);
+      a->fd = open(buf, (a->fd_rw ? O_RDWR : O_RDONLY) | O_CLOEXEC);
       if (a->fd < 0)
        {
          e = snprintf(buf, sizeof(buf), "%s/%04x:%02x/%02x.%d",
@@ -137,7 +137,7 @@ proc_setup(struct pci_dev *d, int rw)
                       d->domain, d->bus, d->dev, d->func);
          if (e < 0 || e >= (int) sizeof(buf))
            a->error("File name too long");
-         a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY);
+         a->fd = open(buf, (a->fd_rw ? O_RDWR : O_RDONLY) | O_CLOEXEC);
        }
       if (a->fd < 0)
        a->warning("Cannot open %s", buf);
index 5a48c0db86285ea226a836a6fd185514c227d77d..3b33a11f79f373671f9b42685be8e07f4b3cdf0d 100644 (file)
@@ -95,7 +95,7 @@ sysfs_get_string(struct pci_dev *d, char *object, char *buf, int mandatory)
   char namebuf[OBJNAMELEN];
 
   sysfs_obj_name(d, object, namebuf);
-  fd = open(namebuf, O_RDONLY);
+  fd = open(namebuf, O_RDONLY|O_CLOEXEC);
   if (fd < 0)
     {
       if (mandatory)
@@ -130,7 +130,7 @@ sysfs_get_resources(struct pci_dev *d)
   int i;
 
   sysfs_obj_name(d, "resource", namebuf);
-  file = fopen(namebuf, "r");
+  file = fopen(namebuf, "re");
   if (!file)
     a->error("Cannot open %s: %s", namebuf, strerror(errno));
   for (i = 0; i < 7; i++)
@@ -236,7 +236,7 @@ sysfs_fill_slots(struct pci_access *a)
       n = snprintf(namebuf, OBJNAMELEN, "%s/%s/%s", dirname, entry->d_name, "address");
       if (n < 0 || n >= OBJNAMELEN)
        a->error("File name too long");
-      file = fopen(namebuf, "r");
+      file = fopen(namebuf, "re");
       /*
        * Old versions of Linux had a fakephp which didn't have an 'address'
        * file.  There's no useful information to be gleaned from these
@@ -312,7 +312,7 @@ sysfs_setup(struct pci_dev *d, int intent)
       if (a->fd_vpd < 0)
        {
          sysfs_obj_name(d, "vpd", namebuf);
-         a->fd_vpd = open(namebuf, O_RDONLY);
+         a->fd_vpd = open(namebuf, O_RDONLY|O_CLOEXEC);
          /* No warning on error; vpd may be absent or accessible only to root */
        }
       return a->fd_vpd;
@@ -322,7 +322,7 @@ sysfs_setup(struct pci_dev *d, int intent)
     {
       sysfs_obj_name(d, "config", namebuf);
       a->fd_rw = a->writeable || intent == SETUP_WRITE_CONFIG;
-      a->fd = open(namebuf, a->fd_rw ? O_RDWR : O_RDONLY);
+      a->fd = open(namebuf, (a->fd_rw ? O_RDWR : O_RDONLY) | O_CLOEXEC);
       if (a->fd < 0)
        a->warning("Cannot open %s", namebuf);
       a->fd_pos = 0;