已合并
fix(init/ueventd): PID 1 稳定性修复 — waitpid 超时(高-5/6) + ueventd NULL 守卫(高-10) + 单测 #4960
fix(init/ueventd): PID 1 稳定性修复 — waitpid 超时(高-5/6) + ueventd NULL 守卫(高-10) + 单测 #4960
已合并
chenjinxiang3创建于 11 天前
chenjinxiang3
chenjinxiang3成员
11 天前

背景

init(PID 1)单线程,多处 waitpid/strstr 无超时/无判空,子进程挂起或 uevent 无 DEVNAME 即冻结/崩溃整机。本 PR 落地其中 3 项"高风险 × 小改动"修复 + 100% 分支覆盖单测。

改动(5 文件,+125/−22,单笔 commit)

1. syncexec/DumpFdInfo waitpid 无超时(init_cmds.c)

SyncExecCommand(cfg syncexec 命令)与 DumpFdInfowaitpid(pid,&status,0) 无超时,异常子进程挂起即冻结 init(违反 §3.2)。新增 WaitPidTimeoutWNOHANG 轮询 100ms,超时 SIGKILL+收尸,返 -1);syncexec 30s、fd dump 5s。

2. appspawn waitpid 无超时(init_service_manager.c)

StopAppSpawnBeforeReboot SIGTERM 后阻塞 waitpid(appspawn),D 态/忽略 SIGTERM 则重启冻结。复用 WaitPidTimeout(5s+SIGKILL),extern 引用 init_cmds.c 中的共享定义——单一来源,不新增头文件。

3. ueventd strstr NULL 解引用(ueventd.c)

HandleRequiredBlockDeviceNodes 未判 deviceNamestrstr,块设备 uevent 不保证带 DEVNAME → NULL 解引用 → ramdisk ueventd -b 段错误、启动失败。增 deviceName != NULL 守卫;日志 NULL 打印 "(null)"。11 折 || 链抽为表驱动 IsRequiredPartitionName(非 static,行为不变,圈复杂度 ≤10)。

测试(在既有文件中新增,100% 分支覆盖)

文件 用例 覆盖分支
cmds_unittest.cpp WaitPidTimeout_ChildExits 子退出 → 返回 status
WaitPidTimeout_InvalidPid 无效 pid → waitpid -1 → 返回 -1
WaitPidTimeout_TimeoutKill 超时 → SIGKILL+收尸 → 返回 -1,WIFSIGNALED && SIGKILL
ueventd_event_unittest.cpp IsRequiredPartitionName_Match 循环匹配 → true
IsRequiredPartitionName_OtherMatch IsOtherPartitionName → true
IsRequiredPartitionName_NoMatch 无匹配 → false

验证

ninja -C out/rk3568 init init_unittestLINK init + LINK init_unittest0 error,0 warning。单测 ARM 架构,需 rk3568 设备/QEMU 运行。

行为变更

  • 正常路径无可观察变化。
  • 异常路径:子进程挂起 → 超时 SIGKILL+返错(不再冻结);无 DEVNAME → 不崩溃(启动继续)。

约束遵循(AGENTS.md §3)

  • 未引入线程/阻塞调用(§3.1.1);超时用 WNOHANG 轮询。
  • 未改 innerkits 导出符号/权限顺序/cfg 加载顺序/feature flags(§3.2)。
  • 函数 ≤50 行、圈复杂度 ≤10、禁用 realloc(§编码规则)。

Signed-off-by: chenjinxiang3 chenjinxiang3@huawei.com

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 chenjinxiang3 的贡献)
chenjinxiang3chenjinxiang3成员
11 天前 关联了issue:startup_init 稳定性修复:PID 1 冻结/堆破坏/崩溃恢复(高-1~高-11,高-13 + P2 11项)
openharmony_ciopenharmony_ci成员
11 天前 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
11 天前 评论:

感谢提交 Pull Requests!如果您提交的PR已经开发完毕,请评论 "start build" 触发门禁,更多交互操作,请访问OpenHarmony社区支持命令清单。如果需要调整订阅PR、Issue的变更状态,请访问订阅链接


Thanks for submitting the pull request. If your Pull Request has already been developed, you can leave a "start build" comment to trigger the gated system. For more commands, please visit OpenHarmony Command List. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
11 天前 添加了label:dco检查成功
chenjinxiang3chenjinxiang3成员
10 天前 推送  1 个提交:45b75b82-fix(init_context): on sub-init read timeout, restart sub-init to avoid stale-result misalignment
此处折叠了112条消息 查看更多
openharmony_ciopenharmony_ci成员
6 天前 关闭了关联的issue
openharmony_ciopenharmony_ci成员
6 天前 合入了pull request,合并节点 SHA:0d03292c5b917befae0cae4383970d7bb37b6920
openharmony_ciopenharmony_ci成员
5 天前 删除了label:waiting_for_review
openharmony_ciopenharmony_ci成员
5 天前 添加了label:merged
openharmony_dcp
openharmony_dcp成员
2 天前 评论:

你因提交次数过多被限制提交,为保障上库效率、避免资源浪费,请先观看学习视频:https://dcp.openharmony.cn/workbench/video/videoDisplay

likedislike