fix(sdk): App 退出日志兜底 — meow_ui_init 安装 SIGTERM/SIGINT 处理器(log_sig_exit: 直写 exit:sigterm 绕过缓冲+exit(0));修 watchdog 返回键杀 App 时日志只有 start 没有 exit 的问题;App 自装处理器(hello BYE)覆盖不受影响 + meow_ui.h 旧日志路径注释更正

meow_ui.a→049fa9db; hello→d0ac55cf; files→3b3bea05; launcher→4f223701; 宿主 widgets PASS
This commit is contained in:
MeowOS committed 2026-08-31 05:30:04 +08:00
1 parent feb3df681c
commit 29e1b35da8
7 files changed
+30 -1

No files matched your search

+25
View File
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>
/* 单行消息上限(超长截断) */
@@ -70,6 +71,8 @@ static int g_log_fallback = 0; /* 1=无卡/写失败,降级 stderr */
static int g_log_open_tried = 0; /* 是否已尝试开首个文件(只试一次,失败则降级) */
static unsigned long g_write_count = 0; /* 累计写入次数(周期总量清理节流) */
static void log_open(void); /* 前向声明(log_sig_exit 在其定义之前使用) */
/* 由 g_log_base + g_log_seq 重建当前文件路径(seq=0 无后缀,>0 追加 _<n>)。 */
static void log_rebuild_file(void)
{
@@ -118,6 +121,28 @@ static void log_init(void)
}
}
/* 退出日志兜底(M2.78):App 被 watchdog 返回键 SIGTERM 时走默认终止,跳过正常
* 路径的 meow_log("exit"),日志只剩 start。SDK 在 meow_ui_init 安装本处理器:
* SIGTERM/SIGINT → 直接 write 一条 exit:<sig>(绕过 stdio 缓冲)→ exit(0)(干净码)。
* App 自装处理器(如 hello 画 BYE)会覆盖本处理器,其 exit(0) 路径不受影响。 */
static void log_sig_exit(int sig)
{
if (!g_log_open_tried) { g_log_open_tried = 1; log_open(); }
if (g_log_fd >= 0) {
char line[128];
int n = snprintf(line, sizeof line, "%llu [%s] INFO exit:%s\n",
(unsigned long long)meow_ui_time_ms(), g_app_id,
sig == SIGTERM ? "sigterm" : "sigint");
if (n > 0) { ssize_t w = write(g_log_fd, line, (size_t)n); (void)w; }
}
exit(0);
}
void meow_log_install_exit_handler(void)
{
signal(SIGTERM, log_sig_exit);
signal(SIGINT, log_sig_exit);
}
/* mkdir -p:逐分量 mkdir(已存在 EEXIST 视为成功)。返回 0=成功,-1=失败。 */
static int log_mkdir_p(const char *path)
{