Fix(logger): preserve queued logs on shutdown; record exit signal

This commit is contained in:
yuanyuanxiang committed 2026-05-27 08:55:14 +02:00
1 parent 268a427172
commit 1fd431ba76
3 files changed
+37 -4

No files matched your search

+12
View File
@@ -786,8 +786,12 @@ static void daemonize()
}
// 信号处理:收到 SIGTERM/SIGINT 时优雅退出
// 注意:handler 内不能调 Mprintf(Logger 用 mutex/string/condvar,非 async-signal-safe),
// 只在这里记 sig_atomic_t 标志位,main 退出循环后再补一行日志。
static volatile sig_atomic_t g_lastSignal = 0;
static void signalHandler(int sig)
{
g_lastSignal = sig;
g_bExit = S_CLIENT_EXIT;
}
@@ -1060,6 +1064,14 @@ int main(int argc, char* argv[])
}
}
// 退出原因留痕:signal handler 不能直接打日志,在这里补一行。
if (g_lastSignal != 0) {
Mprintf(">>> Exit by signal %d (g_bExit=%d)\n",
(int)g_lastSignal, (int)g_bExit);
} else {
Mprintf(">>> Exit normally (g_bExit=%d)\n", (int)g_bExit);
}
Logger::getInstance().stop();
removePidFile();
return 0;