aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-08-26 16:20:59 -0700
committerElliott Hughes <enh@google.com>2014-08-26 16:20:59 -0700
commitf73183f1a34df22b62a3d0bbf82e18d5797c9cde (patch)
tree1bc3c9a47180aaeb2f734e835034a3f6b9ac9d00
parent7b87d441b0f2aa3ad5021ab6bd879a995a1bc2ce (diff)
downloadandroid_bionic-f73183f1a34df22b62a3d0bbf82e18d5797c9cde.tar.gz
android_bionic-f73183f1a34df22b62a3d0bbf82e18d5797c9cde.tar.bz2
android_bionic-f73183f1a34df22b62a3d0bbf82e18d5797c9cde.zip
More cases where libc should use O_CLOEXEC.
Change-Id: Idfa111aeebc5deca2399dae919e8b72eb54c23c0
-rw-r--r--libc/bionic/bionic_systrace.cpp2
-rw-r--r--libc/bionic/dirent.cpp2
-rw-r--r--libc/bionic/malloc_debug_qemu.cpp2
-rw-r--r--libc/bionic/pthread_setname_np.cpp2
-rw-r--r--libc/bionic/system_properties.cpp21
5 files changed, 6 insertions, 23 deletions
diff --git a/libc/bionic/bionic_systrace.cpp b/libc/bionic/bionic_systrace.cpp
index b8e892e72..f5be41553 100644
--- a/libc/bionic/bionic_systrace.cpp
+++ b/libc/bionic/bionic_systrace.cpp
@@ -74,7 +74,7 @@ ScopedTrace::ScopedTrace(const char* message) {
}
if (g_trace_marker_fd == -1) {
- g_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY | O_CLOEXEC);
+ g_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
if (g_trace_marker_fd == -1) {
__libc_fatal("Could not open kernel trace file: %s\n", strerror(errno));
}
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 7abc7f3ec..5e1c7a565 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -78,7 +78,7 @@ DIR* fdopendir(int fd) {
}
DIR* opendir(const char* path) {
- int fd = open(path, O_RDONLY | O_DIRECTORY);
+ int fd = open(path, O_CLOEXEC | O_DIRECTORY | O_RDONLY);
return (fd != -1) ? __allocate_DIR(fd) : NULL;
}
diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp
index b3b604d86..2f4949b12 100644
--- a/libc/bionic/malloc_debug_qemu.cpp
+++ b/libc/bionic/malloc_debug_qemu.cpp
@@ -606,7 +606,7 @@ extern "C" bool malloc_debug_initialize(HashTable*, const MallocDebug* malloc_di
* the memory mapped spaces into writes to an I/O port that emulator
* "listens to" on the other end. Note that until we open and map that
* device, logging to emulator's stdout will not be available. */
- int fd = open("/dev/qemu_trace", O_RDWR);
+ int fd = open("/dev/qemu_trace", O_CLOEXEC | O_RDWR);
if (fd < 0) {
error_log("Unable to open /dev/qemu_trace");
return false;
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index 1ddf81044..7b2fa6b0a 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -67,7 +67,7 @@ int pthread_setname_np(pthread_t t, const char* thread_name) {
}
char comm_name[sizeof(TASK_COMM_FMT) + 8];
snprintf(comm_name, sizeof(comm_name), TASK_COMM_FMT, tid);
- int fd = open(comm_name, O_WRONLY);
+ int fd = open(comm_name, O_CLOEXEC | O_WRONLY);
if (fd == -1) {
return errno;
}
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index ad69cf5f9..411d6bf34 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -201,14 +201,6 @@ static int map_prop_area_rw()
return -1;
}
- // TODO: Is this really required ? Does android run on any kernels that
- // don't support O_CLOEXEC ?
- const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- close(fd);
- return -1;
- }
-
if (ftruncate(fd, PA_SIZE) < 0) {
close(fd);
return -1;
@@ -271,18 +263,9 @@ static int map_fd_ro(const int fd) {
static int map_prop_area()
{
- int fd(open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
- if (fd >= 0) {
- /* For old kernels that don't support O_CLOEXEC */
- const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- close(fd);
- return -1;
- }
- }
-
+ int fd = open(property_filename, O_CLOEXEC | O_NOFOLLOW | O_RDONLY);
bool close_fd = true;
- if ((fd < 0) && (errno == ENOENT)) {
+ if (fd == -1 && errno == ENOENT) {
/*
* For backwards compatibility, if the file doesn't
* exist, we use the environment to get the file descriptor.