已开启
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创建于 4 天前
chenjinxiang3
chenjinxiang3成员
4 天前

背景

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
合并受阻
chenjinxiang3chenjinxiang3成员
4 天前 关联了issue:startup_init 稳定性修复:PID 1 冻结/堆破坏/崩溃恢复(高-1~高-11,高-13 + P2 11项)
openharmony_ciopenharmony_ci成员
4 天前 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
4 天前 评论:

感谢提交 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成员
4 天前 添加了label:dco检查成功
chenjinxiang3chenjinxiang3成员
3 天前 推送  1 个提交:45b75b82-fix(init_context): on sub-init read timeout, restart sub-init to avoid stale-result misalignment
此处折叠了67条消息 查看更多
openharmony_ciopenharmony_ci成员
23 小时前 添加了label:冒烟测试成功
openharmony_ci
openharmony_ci成员
23 小时前 评论:

代码门禁未通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a9bdc9164650f998b1ccf30/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 hispark_taurus_LiteOS success success >>>
2 hispark_taurus_Linux success NA >>>
3 ohos-sdk success NA >>>
4 dayu200 success success >>>
5 dayu200_tdd success NA >>>
6 hispark_pegasus success success >>>
7 master_inner_build failed(联合门禁失败) NA >>>
8 mac-sdk success NA >>>
9 ohos-host_mini_tdd success NA >>>
10 dayu600_7885 success success >>>
11 x86_64_virt success NA >>>
12 hispark_pegasus_3863 success success >>>

likedislike
chenjinxiang3
chenjinxiang3成员
21 小时前 评论:

start build

likedislike
openharmony_ci
openharmony_ci成员
21 小时前 评论:

部分构建失败,仅触发失败构建
门禁构建开始,包含代码编译【master_inner_build编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6a9c18ec64650f998b2ee8fe/runlist

likedislike
openharmony_ci
openharmony_ci成员
19 小时前 评论:

代码门禁未通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a9c18ec64650f998b2ee8fe/runlist

# Device build result package
1 master_inner_build failed(pipeline running timeout) >>>

likedislike