libc should use O_CLOEXEC when opening files for its own use.
Change-Id: I159f1d57e0ca090d837f57854fcef5879b8b8248
diff --git a/libc/bionic/debug_mapinfo.cpp b/libc/bionic/debug_mapinfo.cpp
index d83799a..698ab6b 100644
--- a/libc/bionic/debug_mapinfo.cpp
+++ b/libc/bionic/debug_mapinfo.cpp
@@ -71,7 +71,7 @@
struct mapinfo_t* milist = NULL;
char data[1024]; // Used to read lines as well as to construct the filename.
snprintf(data, sizeof(data), "/proc/%d/maps", pid);
- FILE* fp = fopen(data, "r");
+ FILE* fp = fopen(data, "re");
if (fp != NULL) {
while (fgets(data, sizeof(data), fp) != NULL) {
mapinfo_t* mi = parse_maps_line(data);
diff --git a/libc/bionic/pututline.c b/libc/bionic/pututline.c
index c8427f7..8cbf470 100644
--- a/libc/bionic/pututline.c
+++ b/libc/bionic/pututline.c
@@ -36,7 +36,7 @@
struct utmp u;
long i;
- if (!(f = fopen(_PATH_UTMP, "w+")))
+ if (!(f = fopen(_PATH_UTMP, "w+e")))
return;
while (fread(&u, sizeof(struct utmp), 1, f) == 1)
@@ -55,7 +55,7 @@
fclose(f);
- if (!(f = fopen(_PATH_UTMP, "w+")))
+ if (!(f = fopen(_PATH_UTMP, "w+e")))
return;
fwrite(utmp, sizeof(struct utmp), 1, f);
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp
index 8309f08..d8aac4f 100644
--- a/libc/bionic/sysconf.cpp
+++ b/libc/bionic/sysconf.cpp
@@ -95,7 +95,7 @@
}
static int __sysconf_nprocessors_onln() {
- FILE* fp = fopen("/proc/stat", "r");
+ FILE* fp = fopen("/proc/stat", "re");
if (fp == NULL) {
return 1;
}
@@ -118,7 +118,7 @@
}
static int __get_meminfo(const char* pattern) {
- FILE* fp = fopen("/proc/meminfo", "r");
+ FILE* fp = fopen("/proc/meminfo", "re");
if (fp == NULL) {
return -1;
}