Move init to libbase logging.
Change-Id: Ibfbefeff587a69e948978a037c555fd12a5ade6a
diff --git a/init/init.cpp b/init/init.cpp
index ba91c2a..1495c68 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -86,7 +86,7 @@
ev.events = EPOLLIN;
ev.data.ptr = reinterpret_cast<void*>(fn);
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
- ERROR("epoll_ctl failed: %s\n", strerror(errno));
+ PLOG(ERROR) << "epoll_ctl failed";
}
}
@@ -97,7 +97,7 @@
size_t key_len = strlen(key);
/* The last environment entry is reserved to terminate the list */
- for (n = 0; n < (ARRAY_SIZE(ENV) - 1); n++) {
+ for (n = 0; n < (arraysize(ENV) - 1); n++) {
/* Delete any existing entry for this key */
if (ENV[n] != NULL) {
@@ -117,7 +117,7 @@
}
}
- ERROR("No env. room to store: '%s':'%s'\n", key, val);
+ LOG(ERROR) << "No env. room to store: '" << key << "':'" << val << "'";
return -1;
}
@@ -140,7 +140,7 @@
void handle_control_message(const std::string& msg, const std::string& name) {
Service* svc = ServiceManager::GetInstance().FindServiceByName(name);
if (svc == nullptr) {
- ERROR("no such service '%s'\n", name.c_str());
+ LOG(ERROR) << "no such service '" << name << "'";
return;
}
@@ -151,22 +151,22 @@
} else if (msg == "restart") {
svc->Restart();
} else {
- ERROR("unknown control msg '%s'\n", msg.c_str());
+ LOG(ERROR) << "unknown control msg '" << msg << "'";
}
}
static int wait_for_coldboot_done_action(const std::vector<std::string>& args) {
Timer t;
- NOTICE("Waiting for %s...\n", COLDBOOT_DONE);
+ LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE "...";
// Any longer than 1s is an unreasonable length of time to delay booting.
// If you're hitting this timeout, check that you didn't make your
// sepolicy regular expressions too expensive (http://b/19899875).
if (wait_for_file(COLDBOOT_DONE, 1)) {
- ERROR("Timed out waiting for %s\n", COLDBOOT_DONE);
+ LOG(ERROR) << "Timed out waiting for " COLDBOOT_DONE;
}
- NOTICE("Waiting for %s took %.2fs.\n", COLDBOOT_DONE, t.duration());
+ LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE " took " << t.duration() << "s.";
return 0;
}
@@ -198,11 +198,11 @@
open("/dev/hw_random", O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
if (hwrandom_fd == -1) {
if (errno == ENOENT) {
- ERROR("/dev/hw_random not found\n");
- /* It's not an error to not have a Hardware RNG. */
- result = 0;
+ LOG(ERROR) << "/dev/hw_random not found";
+ // It's not an error to not have a Hardware RNG.
+ result = 0;
} else {
- ERROR("Failed to open /dev/hw_random: %s\n", strerror(errno));
+ PLOG(ERROR) << "Failed to open /dev/hw_random";
}
goto ret;
}
@@ -210,7 +210,7 @@
urandom_fd = TEMP_FAILURE_RETRY(
open("/dev/urandom", O_WRONLY | O_NOFOLLOW | O_CLOEXEC));
if (urandom_fd == -1) {
- ERROR("Failed to open /dev/urandom: %s\n", strerror(errno));
+ PLOG(ERROR) << "Failed to open /dev/urandom";
goto ret;
}
@@ -218,23 +218,22 @@
chunk_size = TEMP_FAILURE_RETRY(
read(hwrandom_fd, buf, sizeof(buf) - total_bytes_written));
if (chunk_size == -1) {
- ERROR("Failed to read from /dev/hw_random: %s\n", strerror(errno));
+ PLOG(ERROR) << "Failed to read from /dev/hw_random";
goto ret;
} else if (chunk_size == 0) {
- ERROR("Failed to read from /dev/hw_random: EOF\n");
+ LOG(ERROR) << "Failed to read from /dev/hw_random: EOF";
goto ret;
}
chunk_size = TEMP_FAILURE_RETRY(write(urandom_fd, buf, chunk_size));
if (chunk_size == -1) {
- ERROR("Failed to write to /dev/urandom: %s\n", strerror(errno));
+ PLOG(ERROR) << "Failed to write to /dev/urandom";
goto ret;
}
total_bytes_written += chunk_size;
}
- INFO("Mixed %zu bytes from /dev/hw_random into /dev/urandom",
- total_bytes_written);
+ LOG(INFO) << "Mixed " << total_bytes_written << " bytes from /dev/hw_random into /dev/urandom";
result = 0;
ret:
@@ -304,7 +303,7 @@
{ "ro.boot.hardware", "ro.hardware", "unknown", },
{ "ro.boot.revision", "ro.revision", "0", },
};
- for (size_t i = 0; i < ARRAY_SIZE(prop_map); i++) {
+ for (size_t i = 0; i < arraysize(prop_map); i++) {
std::string value = property_get(prop_map[i].src_prop);
property_set(prop_map[i].dst_prop, (!value.empty()) ? value.c_str() : prop_map[i].default_value);
}
@@ -318,7 +317,7 @@
std::string dt_file;
android::base::ReadFileToString(file_name, &dt_file);
if (!dt_file.compare("android,firmware")) {
- ERROR("firmware/android is not compatible with 'android,firmware'\n");
+ LOG(ERROR) << "firmware/android is not compatible with 'android,firmware'";
return;
}
@@ -394,7 +393,7 @@
property_audit_data *d = reinterpret_cast<property_audit_data*>(data);
if (!d || !d->name || !d->cr) {
- ERROR("audit_callback invoked with null data arguments!");
+ LOG(ERROR) << "audit_callback invoked with null data arguments!";
return 0;
}
@@ -404,7 +403,7 @@
}
static void security_failure() {
- ERROR("Security failure; rebooting into recovery mode...\n");
+ LOG(ERROR) << "Security failure; rebooting into recovery mode...";
android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
while (true) { pause(); } // never reached
}
@@ -419,9 +418,9 @@
selinux_set_callback(SELINUX_CB_AUDIT, cb);
if (in_kernel_domain) {
- INFO("Loading SELinux policy...\n");
+ LOG(INFO) << "Loading SELinux policy...";
if (selinux_android_load_policy() < 0) {
- ERROR("failed to load policy: %s\n", strerror(errno));
+ PLOG(ERROR) << "failed to load policy";
security_failure();
}
@@ -429,8 +428,7 @@
bool is_enforcing = selinux_is_enforcing();
if (kernel_enforcing != is_enforcing) {
if (security_setenforce(is_enforcing)) {
- ERROR("security_setenforce(%s) failed: %s\n",
- is_enforcing ? "true" : "false", strerror(errno));
+ PLOG(ERROR) << "security_setenforce(%s) failed" << (is_enforcing ? "true" : "false");
security_failure();
}
}
@@ -439,8 +437,8 @@
security_failure();
}
- NOTICE("(Initializing SELinux %s took %.2fs.)\n",
- is_enforcing ? "enforcing" : "non-enforcing", t.duration());
+ LOG(INFO) << "(Initializing SELinux " << (is_enforcing ? "enforcing" : "non-enforcing")
+ << " took " << t.duration() << "s.)";
} else {
selinux_init_all_handles();
}
@@ -480,10 +478,9 @@
// later on. Now that tmpfs is mounted on /dev, we can actually talk
// to the outside world.
open_devnull_stdio();
- klog_init();
- klog_set_level(KLOG_NOTICE_LEVEL);
+ InitKernelLogging(argv);
- NOTICE("init %s started!\n", is_first_stage ? "first stage" : "second stage");
+ LOG(INFO) << "init " << (is_first_stage ? "first stage" : "second stage") << " started!";
if (!is_first_stage) {
// Indicate that booting is in progress to background fw loaders, etc.
@@ -508,13 +505,13 @@
// that the SELinux policy has been loaded.
if (is_first_stage) {
if (restorecon("/init") == -1) {
- ERROR("restorecon failed: %s\n", strerror(errno));
+ PLOG(ERROR) << "restorecon failed";
security_failure();
}
char* path = argv[0];
char* args[] = { path, const_cast<char*>("--second-stage"), nullptr };
if (execv(path, args) == -1) {
- ERROR("execv(\"%s\") failed: %s\n", path, strerror(errno));
+ PLOG(ERROR) << "execv(\"" << path << "\") failed";
security_failure();
}
}
@@ -522,7 +519,7 @@
// These directories were necessarily created before initial policy load
// and therefore need their security context restored to the proper value.
// This must happen before /dev is populated by ueventd.
- NOTICE("Running restorecon...\n");
+ LOG(INFO) << "Running restorecon...";
restorecon("/dev");
restorecon("/dev/socket");
restorecon("/dev/__properties__");
@@ -531,7 +528,7 @@
epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (epoll_fd == -1) {
- ERROR("epoll_create1 failed: %s\n", strerror(errno));
+ PLOG(ERROR) << "epoll_create1 failed";
exit(1);
}
@@ -601,7 +598,7 @@
epoll_event ev;
int nr = TEMP_FAILURE_RETRY(epoll_wait(epoll_fd, &ev, 1, timeout));
if (nr == -1) {
- ERROR("epoll_wait failed: %s\n", strerror(errno));
+ PLOG(ERROR) << "epoll_wait failed";
} else if (nr == 1) {
((void (*)()) ev.data.ptr)();
}