Merge "charger: android_get_control_file on last_kmsg"
This commit is contained in:
commit
ee9ba3efe7
1 changed files with 14 additions and 12 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
#include <linux/netlink.h>
|
#include <linux/netlink.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <cutils/android_get_control_file.h>
|
||||||
#include <cutils/klog.h>
|
#include <cutils/klog.h>
|
||||||
#include <cutils/misc.h>
|
#include <cutils/misc.h>
|
||||||
#include <cutils/properties.h>
|
#include <cutils/properties.h>
|
||||||
|
|
@ -206,10 +207,9 @@ static int64_t curr_time_ms() {
|
||||||
#define MAX_KLOG_WRITE_BUF_SZ 256
|
#define MAX_KLOG_WRITE_BUF_SZ 256
|
||||||
|
|
||||||
static void dump_last_kmsg(void) {
|
static void dump_last_kmsg(void) {
|
||||||
char* buf;
|
std::string buf;
|
||||||
char* ptr;
|
char* ptr;
|
||||||
unsigned sz = 0;
|
size_t len;
|
||||||
int len;
|
|
||||||
|
|
||||||
LOGW("\n");
|
LOGW("\n");
|
||||||
LOGW("*************** LAST KMSG ***************\n");
|
LOGW("*************** LAST KMSG ***************\n");
|
||||||
|
|
@ -221,21 +221,25 @@ static void dump_last_kmsg(void) {
|
||||||
"/proc/last_kmsg",
|
"/proc/last_kmsg",
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < arraysize(kmsg); ++i) {
|
for (size_t i = 0; i < arraysize(kmsg) && buf.empty(); ++i) {
|
||||||
buf = (char*)load_file(kmsg[i], &sz);
|
auto fd = android_get_control_file(kmsg[i]);
|
||||||
if (buf && sz) break;
|
if (fd >= 0) {
|
||||||
|
android::base::ReadFdToString(fd, &buf);
|
||||||
|
} else {
|
||||||
|
android::base::ReadFileToString(kmsg[i], &buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buf || !sz) {
|
if (buf.empty()) {
|
||||||
LOGW("last_kmsg not found. Cold reset?\n");
|
LOGW("last_kmsg not found. Cold reset?\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = min(sz, LAST_KMSG_MAX_SZ);
|
len = min(buf.size(), LAST_KMSG_MAX_SZ);
|
||||||
ptr = buf + (sz - len);
|
ptr = &buf[buf.size() - len];
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
int cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
|
size_t cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
|
||||||
char yoink;
|
char yoink;
|
||||||
char* nl;
|
char* nl;
|
||||||
|
|
||||||
|
|
@ -251,8 +255,6 @@ static void dump_last_kmsg(void) {
|
||||||
ptr += cnt;
|
ptr += cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
LOGW("\n");
|
LOGW("\n");
|
||||||
LOGW("************* END LAST KMSG *************\n");
|
LOGW("************* END LAST KMSG *************\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue