summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'base/logging.cpp')
-rw-r--r--base/logging.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/base/logging.cpp b/base/logging.cpp
index 30d7f8d57..a33da2211 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -54,6 +54,7 @@
54#endif 54#endif
55 55
56#include <android-base/macros.h> 56#include <android-base/macros.h>
57#include <android-base/parseint.h>
57#include <android-base/strings.h> 58#include <android-base/strings.h>
58#include <android-base/threads.h> 59#include <android-base/threads.h>
59 60
@@ -82,6 +83,23 @@ const char* getprogname() {
82 return progname; 83 return progname;
83} 84}
84#endif 85#endif
86
87#if defined(__linux__)
88int OpenKmsg() {
89#if defined(__ANDROID__)
90 // pick up 'file w /dev/kmsg' environment from daemon's init rc file
91 const auto val = getenv("ANDROID_FILE__dev_kmsg");
92 if (val != nullptr) {
93 int fd;
94 if (android::base::ParseInt(val, &fd, 0)) {
95 auto flags = fcntl(fd, F_GETFL);
96 if ((flags != -1) && ((flags & O_ACCMODE) == O_WRONLY)) return fd;
97 }
98 }
99#endif
100 return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
101}
102#endif
85} // namespace 103} // namespace
86 104
87namespace android { 105namespace android {
@@ -150,7 +168,7 @@ void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
150 static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1, 168 static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1,
151 "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity"); 169 "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity");
152 170
153 static int klog_fd = TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC)); 171 static int klog_fd = OpenKmsg();
154 if (klog_fd == -1) return; 172 if (klog_fd == -1) return;
155 173
156 int level = kLogSeverityToKernelLogLevel[severity]; 174 int level = kLogSeverityToKernelLogLevel[severity];