fix: detect scripts and set Type=forking for systemd services#372
fix: detect scripts and set Type=forking for systemd services#372xujin177 wants to merge 1 commit into
Conversation
|
Hi @xujin177. Thanks for your PR. 😃 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: xujin177 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @xujin177. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
When a program is a script that forks child processes (e.g., deepin- security-loader-exec), systemd under Type=simple may incorrectly terminate the service and kill child processes. By detecting script files and setting Type=forking, we ensure the service manager waits for the forking process to complete properly. Log: Fixed script execution handling with proper systemd service type Influence: 1. Test executing script files that fork child processes 2. Verify that scripts with shebang (#!) are correctly identified 3. Ensure non-script executables still use default Type=simple 4. Check that child processes survive parent script exit 5. Validate systemd service lifecycle with forking scripts 6. Test backward compatibility for existing binary executables fix: 检测脚本并为 systemd 服务设置 Type=forking 当程序是一个会 fork 子进程的脚本(如 deepin-security-loader-exec)时,使用 Type=simple 的 systemd 可能错误地终止服务并杀掉子进程。通过检测脚本文件并设置 Type=forking,确保服务管理器正确等待 fork 进程完成。 Log: 修复了脚本执行时 systemd 服务类型的处理 Influence: 1. 测试执行会 fork 子进程的脚本文件 2. 验证带 shebang (#!) 的脚本能被正确识别 3. 确保非脚本可执行文件仍使用默认的 Type=simple 4. 检查子进程在父脚本退出后是否正常存活 5. 验证 systemd 服务生命周期对 fork 脚本的处理 6. 测试对现有二进制可执行文件的向后兼容性 PMS: BUG-366983
| // systemd 在 Type=simple 下会误判服务结束并杀掉子进程,因此脚本使用 Type=forking | ||
| QFile programFile(program); | ||
| if (programFile.open(QIODevice::ReadOnly)) { | ||
| if (programFile.readLine().startsWith("#!")) { |
There was a problem hiding this comment.
性能/内存隐患 (readLine 处理二进制文件):
如果传入的 program 是一个几十兆的 ELF 二进制文件(而不是文本脚本),该文件内部可能很大一段都没有换行符 \n。调用 QFile::readLine() 会让 Qt 持续将二进制数据读入内存,直到遇到偶然的换行符或达到最大限制。这不仅拖慢了启动速度,还白白浪费了内存。
建议修复: 检查 Shebang 只需要读前 2 个字节。应改为:
if (programFile.read(2) == "#!")
When a program is a script that forks child processes (e.g., deepin- security-loader-exec), systemd under Type=simple may incorrectly terminate the service and kill child processes. By detecting script files and setting Type=forking, we ensure the service manager waits for the forking process to complete properly.
Log: Fixed script execution handling with proper systemd service type
Influence:
fix: 检测脚本并为 systemd 服务设置 Type=forking
当程序是一个会 fork 子进程的脚本(如 deepin-security-loader-exec)时,使 用 Type=simple 的 systemd 可能错误地终止服务并杀掉子进程。通过检测脚本文
件并设置 Type=forking,确保服务管理器正确等待 fork 进程完成。
Log: 修复了脚本执行时 systemd 服务类型的处理
Influence:
PMS: BUG-366983