From 18582c4cc079665ae461dca4767a1e0150369458 Mon Sep 17 00:00:00 2001 From: zhangkun Date: Wed, 25 Feb 2026 16:35:43 +0800 Subject: [PATCH] fix: set SyslogIdentifier for pre-launch hook scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue was that when AM (Application Manager) supports pre-launch hooks, a wrapper script is executed before starting the application. However, systemd uses the script name as the SyslogIdentifier in its command line, causing ambiguous identifiers in journalctl logs. To ensure consistent and clear logging, we now explicitly set the SyslogIdentifier to DSG_APP_ID. Changes made: 1. Modified cmdParse() in main.cpp to parse and store the SyslogIdentifier from command line arguments 2. Added logic to append the SyslogIdentifier property to the systemd unit if provided 3. Updated ApplicationService::Launch() to include --SyslogIdentifier parameter with the application ID when constructing the launch command 4. Increased the estimated command size to accommodate the new parameter This ensures that journalctl logs will consistently use the application ID as the identifier, making logs easier to filter and understand regardless of wrapper script names. fix: 为启动前钩子脚本设置系统日志标识符 问题在于当AM支持启动前钩子时,会在启动应用程序前执行一个包装脚本。然 而systemd会使用脚本名称作为命令行中的SyslogIdentifier,导致journalctl 日志中出现歧义的标识符。为确保日志的一致性和清晰度,我们现在明确将 SyslogIdentifier设置为DSG_APP_ID。 具体修改: 1. 修改main.cpp中的cmdParse()函数以解析和存储命令行参数中的 SyslogIdentifier 2. 添加逻辑,在提供SyslogIdentifier时将其附加到systemd单元属性 3. 更新ApplicationService::Launch()方法,在构建启动命令时包含带有应用程 序ID的--SyslogIdentifier参数 4. 增加了预估命令大小以容纳新参数 这确保journalctl日志将始终使用应用程序ID作为标识符,无论包装脚本名称如 何,都能使日志更易于过滤和理解。 --- apps/app-launch-helper/src/main.cpp | 18 ++++++++++++++++++ src/dbus/applicationservice.cpp | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/app-launch-helper/src/main.cpp b/apps/app-launch-helper/src/main.cpp index ab219b6c..1282dc83 100644 --- a/apps/app-launch-helper/src/main.cpp +++ b/apps/app-launch-helper/src/main.cpp @@ -271,6 +271,7 @@ int processKVPair(msg_ptr msg, std::unordered_map cmdParse(msg_ptr &msg, const std::vector &cmdLines) { std::string unitName; + std::string syslogIdentifier; std::unordered_map> props; size_t cursor{0}; @@ -311,6 +312,11 @@ std::optional cmdParse(msg_ptr &msg, const std::vector cmdParse(msg_ptr &msg, const std::vectorid()), instanceRandomUUID); + newCommands << QStringLiteral("--SyslogIdentifier=%1").arg(this->id()); newCommands << QStringLiteral("--SourcePath=%1").arg(m_desktopSource.sourcePath()); newCommands << std::move(cmds);