summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorMark Salyzyn2018-04-06 11:40:26 -0500
committerMark Salyzyn2018-04-09 09:19:33 -0500
commit2507a048abd7ccd0337384fb16c0fa0a4648c4f1 (patch)
tree95593d86624ad8515cc53b9ff0c3111f2245372b /base
parent0289f35b832824757f261775cc730f64a2bb7561 (diff)
downloadplatform-system-core-2507a048abd7ccd0337384fb16c0fa0a4648c4f1.tar.gz
platform-system-core-2507a048abd7ccd0337384fb16c0fa0a4648c4f1.tar.xz
platform-system-core-2507a048abd7ccd0337384fb16c0fa0a4648c4f1.zip
base: kernel logging get pre-opened /dev/kmsg from environment
If the environment has an instance of /dev/kmsg pre-opened, pick up. This happens when an init script has 'file w /dev/kmsg' in the daemon's recipe. libcutils android_get_control_file operations are open-coded to prevent a dependency on libcutils itself. Also check that /dev/kmsg file descriptor is valid and open'd for write only. Test: check to make sure init() kernel logging still works Bug: 77541952 Bug: 77661605 Change-Id: I007553acd594ef0815d23f32f8aa2867518570ba
Diffstat (limited to 'base')
-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];