Merge "More cases where libc should use O_CLOEXEC."
This commit is contained in:
commit
f1e64b5c17
|
@ -74,7 +74,7 @@ ScopedTrace::ScopedTrace(const char* message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_trace_marker_fd == -1) {
|
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) {
|
if (g_trace_marker_fd == -1) {
|
||||||
__libc_fatal("Could not open kernel trace file: %s\n", strerror(errno));
|
__libc_fatal("Could not open kernel trace file: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ DIR* fdopendir(int fd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR* opendir(const char* path) {
|
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;
|
return (fd != -1) ? __allocate_DIR(fd) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* 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
|
* "listens to" on the other end. Note that until we open and map that
|
||||||
* device, logging to emulator's stdout will not be available. */
|
* 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) {
|
if (fd < 0) {
|
||||||
error_log("Unable to open /dev/qemu_trace");
|
error_log("Unable to open /dev/qemu_trace");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -67,7 +67,7 @@ int pthread_setname_np(pthread_t t, const char* thread_name) {
|
||||||
}
|
}
|
||||||
char comm_name[sizeof(TASK_COMM_FMT) + 8];
|
char comm_name[sizeof(TASK_COMM_FMT) + 8];
|
||||||
snprintf(comm_name, sizeof(comm_name), TASK_COMM_FMT, tid);
|
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) {
|
if (fd == -1) {
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,14 +201,6 @@ static int map_prop_area_rw()
|
||||||
return -1;
|
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) {
|
if (ftruncate(fd, PA_SIZE) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -271,18 +263,9 @@ static int map_fd_ro(const int fd) {
|
||||||
|
|
||||||
static int map_prop_area()
|
static int map_prop_area()
|
||||||
{
|
{
|
||||||
int fd(open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
|
int fd = open(property_filename, O_CLOEXEC | O_NOFOLLOW | O_RDONLY);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool close_fd = true;
|
bool close_fd = true;
|
||||||
if ((fd < 0) && (errno == ENOENT)) {
|
if (fd == -1 && errno == ENOENT) {
|
||||||
/*
|
/*
|
||||||
* For backwards compatibility, if the file doesn't
|
* For backwards compatibility, if the file doesn't
|
||||||
* exist, we use the environment to get the file descriptor.
|
* exist, we use the environment to get the file descriptor.
|
||||||
|
|
Loading…
Reference in New Issue