Skip to content

Commit

Permalink
Save the lastest SYSTEM_LAST_KMSG from dropbox when boot up
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jiaxuan-guo authored and sysopenci committed Jun 11, 2024
1 parent 30d8ba5 commit b0f9482
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crashlog/crashutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions crashlog/privconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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""
Expand Down

0 comments on commit b0f9482

Please sign in to comment.