recovery怎么保存log

首先,要说明的是,我想知道或得到recovery过长的所有详细log信息。

但是log 不能保存到/data  或者 /cache  ,又不能保存到/tmp目录下,

因为下次开机的时候,/tmp目录的内容又会清空。

所以只能格式化之后,factory reset 彻底成功后,才把log 从/tmp 拷贝到 /cache下。

//  临时目录

static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";

// 所有log
static const char *LOG_FILE = "/cache/recovery/log";

// 最后一部分log
static const char *LAST_LOG_FILE = "/cache/recovery/last_log";

// factory reset 彻底成功后,会执行

static void finish_recovery(const char *send_intent) {
{
    // Copy logs to cache so the system can find out what happened.
    copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);  //追加
    copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);  //直接覆盖
    copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false);
    ...........................
}

//  拷贝文件的实现

static void
copy_log_file(const char* source, const char* destination, int append) {
    FILE *log = fopen_path(destination, append ? "a" : "w");
    if (log == NULL) {
        LOGE("Can't open %s\n", destination);
    } else {
        FILE *tmplog = fopen(source, "r");
        if (tmplog != NULL) {
            if (append) {
                fseek(tmplog, tmplog_offset, SEEK_SET);  // Since last write
            }
            char buf[4096];
            while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log);
            if (append) {
                tmplog_offset = ftell(tmplog);
            }
            check_and_fclose(tmplog, source);
        }
        check_and_fclose(log, destination);
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值