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""