From 59bde2e8f4dacc059beb7269b86b276ec091ad57 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 7 Oct 2016 13:21:03 -0700 Subject: [PATCH] Use STDERR_FILENO instead of opening /dev/stderr. /dev/stderr is a symlink to /proc/self/fd/2, so this only has different behavior when we're out of file descriptors, or when STDERR_FILENO is in a different state (it's not at the end, it's not writable, etc.). Test: mma Change-Id: Ie99688d810218eca8482ff060373e88c4e001824 --- libc/bionic/libc_logging.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp index 517d047ff..d87944ecb 100644 --- a/libc/bionic/libc_logging.cpp +++ b/libc/bionic/libc_logging.cpp @@ -432,11 +432,6 @@ int __libc_format_fd(int fd, const char* format, ...) { } static int __libc_write_stderr(const char* tag, const char* msg) { - int fd = TEMP_FAILURE_RETRY(open("/dev/stderr", O_CLOEXEC | O_WRONLY | O_APPEND)); - if (fd == -1) { - return -1; - } - iovec vec[4]; vec[0].iov_base = const_cast(tag); vec[0].iov_len = strlen(tag); @@ -447,8 +442,7 @@ static int __libc_write_stderr(const char* tag, const char* msg) { vec[3].iov_base = const_cast("\n"); vec[3].iov_len = 1; - int result = TEMP_FAILURE_RETRY(writev(fd, vec, 4)); - close(fd); + int result = TEMP_FAILURE_RETRY(writev(STDERR_FILENO, vec, 4)); return result; }