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 1fc4205534
commit 3cc4e35794
4 files changed
+30 -1

No files matched your search

+1 -1
View File
@@ -692,7 +692,7 @@ void meow_sheet_free(meow_sheet *s);
/* §9 应用日志(统一日志 API,M2.51 最小可用版) */
/* ============================================================ */
/* app 只需一行 meow_log();SDK 管「写哪/怎么写/过滤/降级/上限」:
* - 路径:<MEOW_LOG_DIR>/apps/<MEOW_LOG_APP>/logs/<启动时间>_<pid>.log
* - 路径:<MEOW_LOG_DIR>/<启动时间>_<pid>.log(MEOW_LOG_DIR 已含包名分层 logs/<包名>)
* (目录不存在 mkdir -p,按 app 分目录),每次启动=新文件,同一次启动内 O_APPEND 追加;
* - 级别过滤:lvl < meow_log_get_level() 丢弃;默认 MEOW_LOG_INFO;
* - 格式:<monotonic_ms> [<app_id>] <LEVEL> message\n;
+1
View File
@@ -1135,6 +1135,7 @@ static void meow_gfx_load_multifont(void)
int meow_ui_init(const meow_ui_opts *opts)
{
if (g_init_ok) return 0;
meow_log_install_exit_handler(); /* M2.78:SIGTERM/SIGINT 兜底写 exit:<sig> 日志 */
int fw = 0, fh = 0;
if (opts) { fw = opts->width; fh = opts->height; }
+3
View File
@@ -102,6 +102,9 @@ void meow_gfx_mark_dirty(int x, int y, int w, int h);
* 解除后由调用方一次 flush 原子上屏,避免覆盖层与 App on_tick 重绘同帧两刷频闪。 */
void meow_gfx_flush_hold(int on);
/* M2.78:安装 SIGTERM/SIGINT 退出日志兜底处理器(meow_ui_log.c;meow_ui_init 调用)。 */
void meow_log_install_exit_handler(void);
/* 绘制期裁剪(MEOW_APP_SDK.md §3,2026-08-31):当前 clip 矩形内才写像素,默认全屏。
* meow_widget_draw(w) 画任何控件前 push 该控件矩形、画完 pop——任何控件(含 W_CUSTOM)
* 画不出自身边界,根治自定义画布越界脏区。可嵌套(入栈/出栈,push 与当前 clip 求交)。
+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)
{