feat(log): App日志目录扁平化为 MeowOS/logs/<包名>/ (agent-198, 用户定案) — launcher MEOW_LOG_DIR 注入改 logs/<appid>+mkdir_p; SDK meow_ui_log.c 去 apps/ 嵌套; 卡可用时一次性迁移 logs/apps/* 并入新路径; APPS.md/APP_LOG_MANAGER.md 同步
launcher→61f6b0db; files→ac2c2781; 编译0warning(新增代码)
This commit is contained in:
1 parent
32a6a8ed1e
commit
5f7e7542bd
6 files changed
+132
-5
No files matched your search
Binary file not shown.
@@ -807,10 +807,12 @@ int launch_app(struct app *a)
|
||||
/* child: exec the app. M2.12 注入 MEOW_LOG_DIR + MEOW_DATA_DIR/MEOW_CACHE_DIR
|
||||
* (exFAT 无 symlink,数据目录用 env 传给应用)。PATH 继承 launcher(含卡上 opt/bin
|
||||
* 若在),卡不在则回退普通 PATH。M2.52 追加注入 MEOW_LOG_APP(app_id)+MEOW_LOG_LEVEL
|
||||
* (读全局 log.level),使 SDK meow_log() 按 app 分离写 apps/<app_id>.log 并做级别过滤。 */
|
||||
* (读全局 log.level),使 SDK meow_log() 按 app 分离写 logs/<id>/<ts>_<pid>.log 并做级别过滤。
|
||||
* M2.x 简化:MEOW_LOG_DIR 从 logs/apps/<id>/logs 改注入 logs/<id>(目录不存在则建)。 */
|
||||
close(execpipe[0]);
|
||||
char *argv[] = { a->exec, NULL };
|
||||
char env_path[320], env_log[320], env_data[320], env_cache[320];
|
||||
char app_log_dir[288];
|
||||
char env_app[MEOW_APP_ID_MAX + 16], env_lvl[48];
|
||||
char env_fpng[400], env_fidx[400], env_fapp[96];
|
||||
char env_mf[24];
|
||||
@@ -823,7 +825,15 @@ int launch_app(struct app *a)
|
||||
snprintf(env_path, sizeof env_path, "PATH=%s", cp ? cp : "/usr/bin:/bin");
|
||||
envp[ne++] = env_path;
|
||||
envp[ne++] = "HOME=/root";
|
||||
if (log_dir[0]) { snprintf(env_log, sizeof env_log, "MEOW_LOG_DIR=%s", log_dir); envp[ne++] = env_log; }
|
||||
/* M2.x 简化:MEOW_LOG_DIR 注入 logs/<id>(id=app_id,空则 "app",与 SDK app 分离前缀一致)。
|
||||
* 目录不存在则用 meow_mkdir_p 建(幂等),失败不阻塞注入——SDK 侧还有 mkdir_p 兜底。 */
|
||||
if (log_dir[0]) {
|
||||
const char *logid = a->id[0] ? a->id : "app";
|
||||
snprintf(app_log_dir, sizeof app_log_dir, "%s/%s", log_dir, logid);
|
||||
meow_mkdir_p(app_log_dir);
|
||||
snprintf(env_log, sizeof env_log, "MEOW_LOG_DIR=%s", app_log_dir);
|
||||
envp[ne++] = env_log;
|
||||
}
|
||||
/* M2.52:MEOW_LOG_APP=app_id(=app.json.package,缺省回退目录名;与注册表一致;无 id 则跳过,SDK 兜底 "app") */
|
||||
if (a->id[0]) { snprintf(env_app, sizeof env_app, "MEOW_LOG_APP=%s", a->id); envp[ne++] = env_app; }
|
||||
/* M2.52:MEOW_LOG_LEVEL 读全局 log.level(error/warn/info/debug→索引0/1/2/3),
|
||||
|
||||
@@ -530,6 +530,8 @@ extern char ipc_sock_path[MEOW_IPC_SOCK_LEN];
|
||||
extern char log_dir[256];
|
||||
extern int log_fd;
|
||||
extern char log_file[256];
|
||||
/* M2.x 应用日志目录简化(apps/<id>/logs → <id>):mkdir -p 幂等;迁移用。 */
|
||||
int meow_mkdir_p(const char *path);
|
||||
extern uint32_t menu_bg;
|
||||
extern int menu_opened_blank;
|
||||
extern int meow_auto_slept;
|
||||
|
||||
Binary file not shown.
@@ -2,6 +2,9 @@
|
||||
/* 本文件由拆分工具从 meow_launcherd.c 按职责搬移;逻辑与原文 0-diff(仅 static 可见性按跨模块需求调整)。*/
|
||||
#include "meow_launcher_internal.h"
|
||||
|
||||
/* M2.x 应用日志目录简化:一次性迁移 logs/apps/<id>/logs → logs/<id>(定义见下,log_open_card 先调用)。 */
|
||||
static void log_migrate_apps(void);
|
||||
|
||||
int log_fd = -1; /* file log fd on the TF card */
|
||||
|
||||
char log_dir[256] = ""; /* "MeowOS/logs" on card, or "" */
|
||||
@@ -133,6 +136,7 @@ int log_open_card(void)
|
||||
{
|
||||
if (log_fd >= 0) return 0;
|
||||
if (!card_available()) return -1;
|
||||
log_migrate_apps(); /* M2.x 一次性迁移:logs/apps/<id>/logs → logs/<id>(幂等,见下) */
|
||||
char ts[64];
|
||||
boot_timestamp(ts, sizeof ts);
|
||||
snprintf(log_dir, sizeof log_dir, "%s", LOG_DIR_CARD);
|
||||
@@ -144,6 +148,117 @@ int log_open_card(void)
|
||||
}
|
||||
|
||||
|
||||
/* M2.x 应用日志目录简化:mkdir -p(幂等,已存在 EEXIST 视为成功)。返回 0=成功 -1=失败。
|
||||
* 供 launcher 为每 App 建新布局日志目录 logs/<id>/ 用(沿用 SDK 同款逐分量 mkdir)。 */
|
||||
int meow_mkdir_p(const char *path)
|
||||
{
|
||||
char tmp[256];
|
||||
size_t len, i;
|
||||
if (!path || !path[0] || strlen(path) >= sizeof tmp) return -1;
|
||||
len = strlen(path);
|
||||
memcpy(tmp, path, len + 1);
|
||||
if (tmp[len - 1] == '/') tmp[len - 1] = '\0'; /* 去尾斜杠 */
|
||||
for (i = 1; i <= strlen(tmp); i++) {
|
||||
if (tmp[i] == '/' || tmp[i] == '\0') {
|
||||
char ch = tmp[i];
|
||||
tmp[i] = '\0';
|
||||
if (tmp[0] && mkdir(tmp, 0755) != 0 && errno != EEXIST) return -1;
|
||||
tmp[i] = ch;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* M2.x 一次性迁移(幂等,代码可后续移除):旧布局 LOG_DIR_CARD/apps/<id>/logs/<file>.log
|
||||
* 并入新布局 LOG_DIR_CARD/<id>/<file>.log,然后删除旧 apps/ 整树。卡可用时随 log_open_card
|
||||
* 跑一次;apps/ 已不存在则直接返回。同卡同 fs,文件用 rename() 移动(目标同名被覆盖——迁移
|
||||
* 内只挪旧文件,不写新日志)。总容量上限纪律不变:应用日志仍由 SDK 按 App 50MB 清理,boot 日志
|
||||
* 仍走 log_cleanup_old()。 */
|
||||
static void log_rm_rf(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(path, &st) != 0) return;
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
DIR *d = opendir(path);
|
||||
if (d) {
|
||||
struct dirent *e;
|
||||
while ((e = readdir(d)) != NULL) {
|
||||
if (e->d_name[0] == '.' && (e->d_name[1] == '\0' ||
|
||||
(e->d_name[1] == '.' && e->d_name[2] == '\0'))) continue;
|
||||
char sub[512];
|
||||
snprintf(sub, sizeof sub, "%s/%s", path, e->d_name);
|
||||
log_rm_rf(sub);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
rmdir(path);
|
||||
} else {
|
||||
unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
static void log_migrate_apps(void)
|
||||
{
|
||||
char old_root[512], old_dir[512], old_logs[512], new_dir[512];
|
||||
DIR *d, *dl, *dd;
|
||||
struct dirent *e;
|
||||
|
||||
snprintf(old_root, sizeof old_root, "%s/apps", LOG_DIR_CARD);
|
||||
d = opendir(old_root);
|
||||
if (!d) return; /* 旧路径不存在,无需迁移 */
|
||||
|
||||
while ((e = readdir(d)) != NULL) {
|
||||
struct stat st;
|
||||
if (e->d_name[0] == '.') continue;
|
||||
snprintf(old_dir, sizeof old_dir, "%s/%s", old_root, e->d_name);
|
||||
if (stat(old_dir, &st) != 0 || !S_ISDIR(st.st_mode)) continue;
|
||||
|
||||
snprintf(new_dir, sizeof new_dir, "%s/%s", LOG_DIR_CARD, e->d_name);
|
||||
if (meow_mkdir_p(new_dir) != 0) continue; /* 新目录建不了,跳过该 App */
|
||||
|
||||
/* 旧布局 apps/<id>/logs/<file>.log → logs/<id>/<file>.log */
|
||||
snprintf(old_logs, sizeof old_logs, "%s/logs", old_dir);
|
||||
dl = opendir(old_logs);
|
||||
if (dl) {
|
||||
struct dirent *el;
|
||||
while ((el = readdir(dl)) != NULL) {
|
||||
struct stat stl;
|
||||
char src[512], dst[512];
|
||||
if (el->d_name[0] == '.') continue;
|
||||
snprintf(src, sizeof src, "%s/%s", old_logs, el->d_name);
|
||||
if (stat(src, &stl) != 0 || !S_ISREG(stl.st_mode)) continue;
|
||||
snprintf(dst, sizeof dst, "%s/%s", new_dir, el->d_name);
|
||||
rename(src, dst);
|
||||
}
|
||||
closedir(dl);
|
||||
}
|
||||
|
||||
/* 早期设计若直接把 .log 散在 apps/<id>/ 下,一并并入(跳过已处理的 logs/ 子目录) */
|
||||
dd = opendir(old_dir);
|
||||
if (dd) {
|
||||
struct dirent *ed;
|
||||
while ((ed = readdir(dd)) != NULL) {
|
||||
struct stat stf;
|
||||
char src[512], dst[512];
|
||||
if (ed->d_name[0] == '.') continue;
|
||||
if (strcmp(ed->d_name, "logs") == 0) continue;
|
||||
snprintf(src, sizeof src, "%s/%s", old_dir, ed->d_name);
|
||||
if (stat(src, &stf) != 0 || !S_ISREG(stf.st_mode)) continue;
|
||||
snprintf(dst, sizeof dst, "%s/%s", new_dir, ed->d_name);
|
||||
rename(src, dst);
|
||||
}
|
||||
closedir(dd);
|
||||
}
|
||||
|
||||
log_rm_rf(old_dir);
|
||||
}
|
||||
closedir(d);
|
||||
rmdir(old_root); /* apps/ 清空则删;非空则忽略 */
|
||||
fprintf(stderr, "log_migrate: logs/apps/* -> logs/<id> done\n");
|
||||
}
|
||||
|
||||
|
||||
/* flush the /tmp boot buffer into the file log (once the card mounts) */
|
||||
void log_poll_card(void)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user