From b0f94822236719f1c021ce5169c79a440714789a Mon Sep 17 00:00:00 2001 From: "Guo, Jade" Date: Tue, 29 Aug 2023 15:16:49 +0800 Subject: [PATCH] Save the lastest SYSTEM_LAST_KMSG from dropbox when boot up Dropbox generates a SYSTEM_LAST_KMSG file each time when the system reboot, power down, or crash. And this information could be very useful for debug. So we check the dropbox and copy its latest SYSTEM_LAST_KMSG file to the boot information folder. Check the history_event to find this folder and more information. Original-Tracked-On: OAM-111964 Tracked-On: OAM-120395 Signed-off-by: Jade Guo --- crashlog/crashutils.c | 32 ++++++++++++++++++++++++++++++++ crashlog/privconfig.h | 1 + 2 files changed, 33 insertions(+) diff --git a/crashlog/crashutils.c b/crashlog/crashutils.c index 89b7bd3..4c225ba 100755 --- a/crashlog/crashutils.c +++ b/crashlog/crashutils.c @@ -161,8 +161,35 @@ unsigned long long get_uptime(int refresh, int *error) return time_ns; } +// Find system last kmsg from dropbox +static int find_system_last_kmsg(char source[], int source_length) { + struct dirent *entry; + DIR *dir = opendir(DROPBOX_DIR); + int file_exist = 0; + + if (source == NULL) { + LOGE("source is NULL.\n"); + return file_exist; + } + if (dir == NULL) { + LOGE("No such directory: %s\n",DROPBOX_DIR); + return file_exist; + } + while ((entry = readdir(dir)) != NULL) { + if (strstr(entry->d_name, DROPBOX_LAST_KMSG) && sizeof(entry->d_name) < source_length) { + if (strncmp(source, entry->d_name, sizeof(entry->d_name)) < 0) { + strncpy(source, entry->d_name, sizeof(entry->d_name)); + file_exist = 1; + } + } + } + return file_exist; +} + void do_last_kmsg_copy(char *dir) { char destion[PATHMAX]; + char source[PATHMAX]; + char sourcepath[PATHMAX]; if ( file_exists(LAST_KMSG) ) { snprintf(destion, sizeof(destion), "%s/%s", dir, LAST_KMSG_FILE); @@ -178,6 +205,11 @@ void do_last_kmsg_copy(char *dir) { snprintf(destion, sizeof(destion), "%s/%s", dir, FTRACE_RAMOOPS_FILE); do_copy_tail(FTRACE_RAMOOPS, destion, MAXFILESIZE); } + if (find_system_last_kmsg(source, sizeof(source))) { + snprintf(destion, sizeof(destion), "%s/%s", dir, source); + snprintf(sourcepath, sizeof(sourcepath), "%s/%s", DROPBOX_DIR, source); + do_copy_tail(sourcepath, destion, MAXFILESIZE); + } } void do_last_fw_msg_copy(char *dir) { diff --git a/crashlog/privconfig.h b/crashlog/privconfig.h index 0ce6ce5..72d8eb5 100755 --- a/crashlog/privconfig.h +++ b/crashlog/privconfig.h @@ -413,6 +413,7 @@ extern enum crashlog_mode g_crashlog_mode; #define LOG_FABRICTEMP LOGS_DIR "/fabric_temp" #define CONSOLE_NAME "console" #define LAST_KMSG_FILE "last_kmsg" +#define DROPBOX_LAST_KMSG "SYSTEM_LAST_KMSG" #define CONSOLE_RAMOOPS_FILE "console-ramoops" #define DMESG_RAMOOPS_FILE "dmesg-ramoops" #define CONSOLE_RAMOOPS_FILE_NUM(x) "console-ramoops-"#x""