1.FirstStageMain
//android10\system\core\init\first_stage_init.cpp
int FirstStageMain(int argc, char** argv) {
// Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually
// talk to the outside world...
InitKernelLogging(argv);//初始化日志
}
2.InitKernelLogging
//android10\system\core\init\util.cpp
void InitKernelLogging(char** argv) {
SetFatalRebootTarget();
android::base::InitLogging(argv, &android::base::KernelLogger, InitAborter);
}
3.KernelLogger
//android10\system\core\base\logging.cpp
void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
const char* tag, const char*, unsigned int, const char* msg) {
static int klog_fd = OpenKmsg();
}
4.OpenKmsg
//android10\system\core\base\logging.cpp
#if defined(__linux__)
static int OpenKmsg() {
#if defined(__ANDROID__)
// pick up 'file w /dev/kmsg' environment from daemon's init rc file
//在 Android 中用于获取名为 "ANDROID_FILE__dev_kmsg" 的环境变量的值的函数
const auto val = getenv("ANDROID_FILE__dev_kmsg");
if (val != nullptr) {
int fd;
if (android::base::ParseInt(val, &fd, 0)) {
auto flags = fcntl(fd, F_GETFL);
if ((flags != -1) && ((flags & O_ACCMODE) == O_WRONLY)) return fd;
}
}
#endif
//打开/dev/kmsg文件
return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
}
#endif
文章来源地址https://www.toymoban.com/news/detail-782720.html
文章来源:https://www.toymoban.com/news/detail-782720.html
到了这里,关于android系列-init 初始化日志的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!