diff options
author | Josh Gao <jmgao@google.com> | 2018-06-01 15:30:54 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2018-07-19 14:28:54 -0700 |
commit | f6e5b582604715729b09db3e36a7aeb8c24b36a4 (patch) | |
tree | 1d68c449355f88a0652d3c1e2d6679b54fce1b20 /libc/async_safe/async_safe_log.cpp | |
parent | ad596bf4fc406c0940d0f76f6b7c4ff22ecee7ac (diff) |
Introduce api to track fd ownership in libc.
Add two functions to allow objects that own a file descriptor to
enforce that only they can close their file descriptor.
Use them in FILE* and DIR*.
Bug: http://b/110100358
Test: bionic_unit_tests
Test: aosp/master boots without errors
Test: treehugger
Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
Diffstat (limited to 'libc/async_safe/async_safe_log.cpp')
-rw-r--r-- | libc/async_safe/async_safe_log.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp index 1018ef5e0..c6b8b5352 100644 --- a/libc/async_safe/async_safe_log.cpp +++ b/libc/async_safe/async_safe_log.cpp @@ -37,6 +37,7 @@ #include <string.h> #include <sys/mman.h> #include <sys/socket.h> +#include <sys/syscall.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/un.h> @@ -50,6 +51,12 @@ #include "private/ErrnoRestorer.h" #include "private/ScopedPthreadMutexLocker.h" +// Don't call libc's close, since it might call back into us as a result of fdsan. +#pragma GCC poison close +static int __close(int fd) { + return syscall(__NR_close, fd); +} + // Must be kept in sync with frameworks/base/core/java/android/util/EventLog.java. enum AndroidEventLogType { EVENT_TYPE_INT = 0, @@ -462,7 +469,7 @@ static int open_log_socket() { strlcpy(u.addrUn.sun_path, "/dev/socket/logdw", sizeof(u.addrUn.sun_path)); if (TEMP_FAILURE_RETRY(connect(log_fd, &u.addr, sizeof(u.addrUn))) != 0) { - close(log_fd); + __close(log_fd); return -1; } @@ -504,7 +511,7 @@ int async_safe_write_log(int priority, const char* tag, const char* msg) { vec[5].iov_len = strlen(msg) + 1; int result = TEMP_FAILURE_RETRY(writev(main_log_fd, vec, sizeof(vec) / sizeof(vec[0]))); - close(main_log_fd); + __close(main_log_fd); return result; } |