/* get_log_file_* only used to copy regular file which can be mmaped */ static void get_log_file_complete(const char *despath, const char *srcpath) { const int ret = do_copy_tail(srcpath, despath, 0); if (ret < 0) { LOGE("copy (%s) failed, error (%s)\n", srcpath, strerror(errno)); } }
void copy_bplogs(const char *patern, const char *extra, int dir, int limit) { char src[PATHMAX], dst[PATHMAX], prop[PROPERTY_VALUE_MAX]; struct stat info; /*first bplog is ethed "persist.service.mts.output" or "persist.service.mts.output".istp * and will be copied in bplog.istp*/ property_get("persist.service.mts.output", prop, BPLOG_FILE_0); if(file_exists(prop)) { strncpy(src, prop, PROPERTY_VALUE_MAX); } else { snprintf(src, PATHMAX, "%s%s", prop, BPLOG_FILE_0_EXT); } snprintf(dst, PATHMAX, "%s%d/%s%s%s", patern, dir, strrchr(prop,'/')+1, extra, BPLOG_FILE_0_EXT); if(stat(src, &info) == 0) { do_copy_tail(src, dst, limit); if(info.st_size < 1*MB) { snprintf(src, PATHMAX, "%s%s", prop, BPLOG_FILE_1_EXT); snprintf(dst, PATHMAX, "%s%d/%s%s%s", patern, dir, strrchr(prop,'/')+1, extra, BPLOG_FILE_1_EXT); do_copy_tail(src, dst, limit); } } }
void do_log_copy(char *mode, int dir, const char* timestamp, int type) { char destination[PATHMAX], bp_extra[PATHMAX], *logfile0, *logfile1, *extension; struct stat info; char *dir_pattern = CRASH_DIR; int limit = MAXFILESIZE; switch (type) { case APLOG_TYPE: case APLOG_STATS_TYPE: case KDUMP_TYPE: #ifndef CONFIG_APLOG flush_aplog(APLOG, NULL, NULL, NULL); #endif logfile0 = APLOG_FILE_0; logfile1 = APLOG_FILE_1; extension = ""; if (type == APLOG_STATS_TYPE) dir_pattern = STATS_DIR; else if (type == KDUMP_TYPE) dir_pattern = KDUMP_CRASH_DIR; break; case BPLOG_TYPE: case BPLOG_STATS_TYPE: if (type == BPLOG_STATS_TYPE) dir_pattern = STATS_DIR; snprintf(bp_extra, sizeof(bp_extra), "_%s_%s", mode, timestamp); copy_bplogs(dir_pattern, bp_extra, dir, limit); return; case BPLOG_TYPE_OLD: logfile0 = compute_bp_log(BPLOG_FILE_1_OLD_EXT); // BPLOG_FILE_1_OLD; logfile1 = compute_bp_log(BPLOG_FILE_2_OLD_EXT); // BPLOG_FILE_2_OLD; extension = ".istp"; /* limit size remains for old bplogs*/ break; default: /* Ignore unknown type, just return */ return; } if(logfile0 && stat(logfile0, &info) == 0) { snprintf(destination,sizeof(destination), "%s%d/%s_%s_%s%s", dir_pattern, dir, strrchr(logfile0,'/')+1, mode, timestamp, extension); do_copy_tail(logfile0, destination, limit); if(logfile1 && info.st_size < 1*MB) { snprintf(destination,sizeof(destination), "%s%d/%s_%s_%s%s", dir_pattern, dir, strrchr(logfile1,'/')+1, mode, timestamp, extension); do_copy_tail(logfile1, destination, limit); } #ifndef CONFIG_APLOG remove(APLOG_FILE_0); #endif } switch (type) { case APLOG_TYPE: case APLOG_STATS_TYPE: case KDUMP_TYPE: //nothing to do break; case BPLOG_TYPE_OLD: free(logfile0); free(logfile1); break; default: /* Ignore unknown type, just return */ return; } }