Merge \\\"Fix early init logging.\\\" am: 6d232ab4de am: 1cbd1f5016

am: 7e336c8fe5

Change-Id: Id22974510c241cc8b62c3737de36c1e5941420e3
This commit is contained in:
Elliott Hughes 2016-07-27 15:36:13 +00:00 committed by android-build-merger
commit a9f814239b
4 changed files with 14 additions and 17 deletions

View file

@ -118,7 +118,7 @@ void Action::ExecuteCommand(const Command& command) const {
Timer t; Timer t;
int result = command.InvokeFunc(); int result = command.InvokeFunc();
if (klog_get_level() >= KLOG_INFO_LEVEL) { if (klog_get_level() >= KLOG_DEBUG_LEVEL) {
std::string trigger_name = BuildTriggersString(); std::string trigger_name = BuildTriggersString();
std::string cmd_str = command.BuildCommandString(); std::string cmd_str = command.BuildCommandString();
std::string source = command.BuildSourceString(); std::string source = command.BuildSourceString();

View file

@ -29,6 +29,7 @@
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -487,12 +488,11 @@ int main(int argc, char** argv) {
mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC)); mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
mount("sysfs", "/sys", "sysfs", 0, NULL); mount("sysfs", "/sys", "sysfs", 0, NULL);
mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL); mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL);
mknod("/dev/kmsg", S_IFCHR | 0600, makedev(1, 11));
} }
// We must have some place other than / to create the device nodes for // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually
// kmsg and null, otherwise we won't be able to remount / read-only // talk to the outside world...
// later on. Now that tmpfs is mounted on /dev, we can actually talk
// to the outside world.
InitKernelLogging(argv); InitKernelLogging(argv);
LOG(INFO) << "init " << (is_first_stage ? "first stage" : "second stage") << " started!"; LOG(INFO) << "init " << (is_first_stage ? "first stage" : "second stage") << " started!";
@ -536,6 +536,7 @@ int main(int argc, char** argv) {
// This must happen before /dev is populated by ueventd. // This must happen before /dev is populated by ueventd.
LOG(INFO) << "Running restorecon..."; LOG(INFO) << "Running restorecon...";
restorecon("/dev"); restorecon("/dev");
restorecon("/dev/kmsg");
restorecon("/dev/socket"); restorecon("/dev/socket");
restorecon("/dev/__properties__"); restorecon("/dev/__properties__");
restorecon("/property_contexts"); restorecon("/property_contexts");

View file

@ -26,8 +26,12 @@
#include <selinux/selinux.h> #include <selinux/selinux.h>
static const int kLogSeverityToKLogLevel[] = { static const int kLogSeverityToKLogLevel[] = {
KLOG_NOTICE_LEVEL, KLOG_DEBUG_LEVEL, KLOG_INFO_LEVEL, [android::base::VERBOSE] = KLOG_DEBUG_LEVEL,
KLOG_WARNING_LEVEL, KLOG_ERROR_LEVEL, KLOG_ERROR_LEVEL, [android::base::DEBUG] = KLOG_DEBUG_LEVEL,
[android::base::INFO] = KLOG_INFO_LEVEL,
[android::base::WARNING] = KLOG_WARNING_LEVEL,
[android::base::ERROR] = KLOG_ERROR_LEVEL,
[android::base::FATAL] = KLOG_ERROR_LEVEL,
}; };
static_assert(arraysize(kLogSeverityToKLogLevel) == android::base::FATAL + 1, static_assert(arraysize(kLogSeverityToKLogLevel) == android::base::FATAL + 1,
"Mismatch in size of kLogSeverityToKLogLevel and values in LogSeverity"); "Mismatch in size of kLogSeverityToKLogLevel and values in LogSeverity");
@ -68,7 +72,7 @@ void InitKernelLogging(char* argv[]) {
if (fd > 2) close(fd); if (fd > 2) close(fd);
android::base::InitLogging(argv, &KernelLogger); android::base::InitLogging(argv, &KernelLogger);
klog_set_level(KLOG_NOTICE_LEVEL); klog_set_level(KLOG_INFO_LEVEL);
} }
int selinux_klog_callback(int type, const char *fmt, ...) { int selinux_klog_callback(int type, const char *fmt, ...) {

View file

@ -37,15 +37,7 @@ void klog_set_level(int level) {
} }
static int __open_klog(void) { static int __open_klog(void) {
int fd = open("/dev/kmsg", O_WRONLY | O_CLOEXEC); return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
if (fd == -1) {
static const char* name = "/dev/__kmsg__";
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 11) == 0) {
fd = open(name, O_WRONLY | O_CLOEXEC);
unlink(name);
}
}
return fd;
} }
#define LOG_BUF_MAX 512 #define LOG_BUF_MAX 512