Make logging fall back to /dev/stderr if we're on the host.

Otherwise you get no logging, which sucks.

Change-Id: Iea1e8f996461afbb217a55711b7967005c39cfcb
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 6bf7415..635f8d1 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -419,9 +419,34 @@
   return os.total;
 }
 
+static int __libc_write_stderr(const char* tag, const char* msg) {
+  int fd = TEMP_FAILURE_RETRY(open("/dev/stderr", O_CLOEXEC | O_WRONLY));
+  if (fd == -1) {
+    return -1;
+  }
+
+  iovec vec[4];
+  vec[0].iov_base = const_cast<char*>(tag);
+  vec[0].iov_len = strlen(tag);
+  vec[1].iov_base = const_cast<char*>(": ");
+  vec[1].iov_len = 2;
+  vec[2].iov_base = const_cast<char*>(msg);
+  vec[2].iov_len = strlen(msg) + 1;
+  vec[3].iov_base = const_cast<char*>("\n");
+  vec[3].iov_len = 1;
+
+  int result = TEMP_FAILURE_RETRY(writev(fd, vec, 4));
+  close(fd);
+  return result;
+}
+
 static int __libc_write_log(int priority, const char* tag, const char* msg) {
   int main_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/main", O_CLOEXEC | O_WRONLY));
   if (main_log_fd == -1) {
+    if (errno == ENOTDIR) {
+      // /dev/log isn't a directory? Maybe we're running on the host? Try stderr instead.
+      return __libc_write_stderr(tag, msg);
+    }
     return -1;
   }