Move init to libbase logging.
Change-Id: Ibfbefeff587a69e948978a037c555fd12a5ade6a
diff --git a/init/devices.cpp b/init/devices.cpp
index 32fec52..5e12f25 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -174,13 +174,14 @@
}
std::string attr_file = path + "/" + dp->attr;
- INFO("fixup %s %d %d 0%o\n", attr_file.c_str(), dp->uid, dp->gid, dp->perm);
+ LOG(INFO) << "fixup " << attr_file
+ << " " << dp->uid << " " << dp->gid << " " << std::oct << dp->perm;
chown(attr_file.c_str(), dp->uid, dp->gid);
chmod(attr_file.c_str(), dp->perm);
}
if (access(path.c_str(), F_OK) == 0) {
- INFO("restorecon_recursive: %s\n", path.c_str());
+ LOG(INFO) << "restorecon_recursive: " << path;
restorecon_recursive(path.c_str());
}
}
@@ -241,8 +242,7 @@
mode = get_device_perm(path, links, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
if (selabel_lookup_best_match(sehandle, &secontext, path, links, mode)) {
- ERROR("Device '%s' not created; cannot find SELinux label (%s)\n",
- path, strerror(errno));
+ PLOG(ERROR) << "Device '" << path << "' not created; cannot find SELinux label";
return;
}
setfscreatecon(secontext);
@@ -261,8 +261,7 @@
char* fcon = nullptr;
int rc = lgetfilecon(path, &fcon);
if (rc < 0) {
- ERROR("Cannot get SELinux label on '%s' device (%s)\n",
- path, strerror(errno));
+ PLOG(ERROR) << "Cannot get SELinux label on '" << path << "' device";
goto out;
}
@@ -270,8 +269,7 @@
freecon(fcon);
if (different && lsetfilecon(path, secontext)) {
- ERROR("Cannot set '%s' SELinux label on '%s' device (%s)\n",
- secontext, path, strerror(errno));
+ PLOG(ERROR) << "Cannot set '" << secontext << "' SELinux label on '" << path << "' device";
}
}
@@ -295,7 +293,7 @@
name += 9;
}
- INFO("adding platform device %s (%s)\n", name, path);
+ LOG(INFO) << "adding platform device " << name << " (" << path << ")";
bus = (platform_node*) calloc(1, sizeof(struct platform_node));
bus->path = strdup(path);
@@ -334,7 +332,7 @@
list_for_each_reverse(node, &platform_names) {
bus = node_to_item(node, struct platform_node, list);
if (!strcmp(path, bus->path)) {
- INFO("removing platform device %s\n", bus->name);
+ LOG(INFO) << "removing platform device " << bus->name;
free(bus->path);
list_remove(node);
free(bus);
@@ -423,9 +421,9 @@
}
if (LOG_UEVENTS) {
- INFO("event { '%s', '%s', '%s', '%s', %d, %d }\n",
- uevent->action, uevent->path, uevent->subsystem,
- uevent->firmware, uevent->major, uevent->minor);
+ LOG(INFO) << android::base::StringPrintf("event { '%s', '%s', '%s', '%s', %d, %d }",
+ uevent->action, uevent->path, uevent->subsystem,
+ uevent->firmware, uevent->major, uevent->minor);
}
}
@@ -509,15 +507,16 @@
return NULL;
memset(links, 0, sizeof(char *) * 4);
- INFO("found %s device %s\n", type, device);
+ LOG(INFO) << "found " << type << " device " << device;
snprintf(link_path, sizeof(link_path), "/dev/block/%s/%s", type, device);
if (uevent->partition_name) {
p = strdup(uevent->partition_name);
sanitize(p);
- if (strcmp(uevent->partition_name, p))
- NOTICE("Linking partition '%s' as '%s'\n", uevent->partition_name, p);
+ if (strcmp(uevent->partition_name, p)) {
+ LOG(VERBOSE) << "Linking partition '" << uevent->partition_name << "' as '" << p << "'";
+ }
if (asprintf(&links[link_num], "%s/by-name/%s", link_path, p) > 0)
link_num++;
else
@@ -595,8 +594,7 @@
/* too-long names would overrun our buffer */
if(strlen(name) > len) {
- ERROR("DEVPATH=%s exceeds %u-character limit on filename; ignoring event\n",
- name, len);
+ LOG(ERROR) << "DEVPATH=" << name << " exceeds " << len << "-character limit on filename; ignoring event";
return NULL;
}
@@ -631,12 +629,11 @@
{
int s = snprintf(devpath, DEVPATH_LEN, "%s/%s", dirname, devname);
if (s < 0) {
- ERROR("failed to assemble device path (%s); ignoring event\n",
- strerror(errno));
+ PLOG(ERROR) << "failed to assemble device path; ignoring event";
return false;
} else if (s >= DEVPATH_LEN) {
- ERROR("%s/%s exceeds %u-character limit on path; ignoring event\n",
- dirname, devname, DEVPATH_LEN);
+ LOG(ERROR) << dirname << "/" << devname
+ << " exceeds " << DEVPATH_LEN << "-character limit on path; ignoring event";
return false;
}
return true;
@@ -680,8 +677,7 @@
break;
default:
- ERROR("%s subsystem's devpath option is not set; ignoring event\n",
- uevent->subsystem);
+ LOG(ERROR) << uevent->subsystem << " subsystem's devpath option is not set; ignoring event";
return;
}
@@ -737,9 +733,8 @@
} else if(!strncmp(uevent->subsystem, "sound", 5)) {
base = "/dev/snd/";
make_dir(base, 0755);
- } else if(!strncmp(uevent->subsystem, "misc", 4) &&
- !strncmp(name, "log_", 4)) {
- INFO("kernel logger is deprecated\n");
+ } else if(!strncmp(uevent->subsystem, "misc", 4) && !strncmp(name, "log_", 4)) {
+ LOG(INFO) << "kernel logger is deprecated";
base = "/dev/log/";
make_dir(base, 0755);
name += 4;
@@ -818,8 +813,7 @@
size_t i;
int booting = is_booting();
- INFO("firmware: loading '%s' for '%s'\n",
- uevent->firmware, uevent->path);
+ LOG(INFO) << "firmware: loading '" << uevent->firmware << "' for '" << uevent->path << "'";
l = asprintf(&root, SYSFS_PREFIX"%s/", uevent->path);
if (l == -1)
@@ -842,7 +836,7 @@
goto loading_close_out;
try_loading_again:
- for (i = 0; i < ARRAY_SIZE(firmware_dirs); i++) {
+ for (i = 0; i < arraysize(firmware_dirs); i++) {
char *file = NULL;
l = asprintf(&file, "%s/%s", firmware_dirs[i], uevent->firmware);
if (l == -1)
@@ -850,10 +844,11 @@
fw_fd = open(file, O_RDONLY|O_CLOEXEC);
free(file);
if (fw_fd >= 0) {
- if(!load_firmware(fw_fd, loading_fd, data_fd))
- INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware);
- else
- INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware);
+ if (!load_firmware(fw_fd, loading_fd, data_fd)) {
+ LOG(INFO) << "firmware: copy success { '" << root << "', '" << uevent->firmware << "' }";
+ } else {
+ LOG(ERROR) << "firmware: copy failure { '" << root << "', '" << uevent->firmware << "' }";
+ }
break;
}
}
@@ -866,7 +861,7 @@
booting = is_booting();
goto try_loading_again;
}
- INFO("firmware: could not open '%s': %s\n", uevent->firmware, strerror(errno));
+ PLOG(ERROR) << "firmware: could not open '" << uevent->firmware << "'";
write(loading_fd, "-1", 2);
goto data_close_out;
}
@@ -900,7 +895,7 @@
process_firmware_event(uevent);
_exit(EXIT_SUCCESS);
} else if (pid < 0) {
- ERROR("could not fork to process firmware event: %s\n", strerror(errno));
+ PLOG(ERROR) << "could not fork to process firmware event";
}
}
@@ -996,7 +991,7 @@
fcntl(device_fd, F_SETFL, O_NONBLOCK);
if (access(COLDBOOT_DONE, F_OK) == 0) {
- NOTICE("Skipping coldboot, already done!\n");
+ LOG(VERBOSE) << "Skipping coldboot, already done!";
return;
}
@@ -1005,7 +1000,7 @@
coldboot("/sys/block");
coldboot("/sys/devices");
close(open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000));
- NOTICE("Coldboot took %.2fs.\n", t.duration());
+ LOG(INFO) << "Coldboot took " << t.duration() << "s.";
}
int get_device_fd()