Merge "More cases where libc should use O_CLOEXEC."

This commit is contained in:
Elliott Hughes 2014-08-26 23:23:58 +00:00 committed by Gerrit Code Review
commit f1e64b5c17
5 changed files with 6 additions and 23 deletions

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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.