Repository navigation
fix(cmd/start): use absolute executable path for child process - #2125
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a Windows-specific bug where the start command fails to spawn a child process when the executable is invoked via a relative path. The fix uses os.Executable() instead of os.Args[0] to obtain the absolute path to the executable, ensuring reliable subprocess spawning across all operating systems.
Changes:
- Replace
os.Args[0]withos.Executable()for obtaining the executable path - Pass user arguments from
startcommand toservercommand viaos.Args[2:] - Add duplicate detection to avoid appending
--force-bin-dirwhen already present
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
568c25a to
abe5737
Compare
abe5737 to
ba8a0d8
Compare
a31fd53 to
7bea29c
Compare
pikachuren
left a comment
There was a problem hiding this comment.
🙏 感谢 @abcqqoo 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
🎯 结论
✅ 建议 Approve(由维护者人工确认)— 修正了一处真实缺陷,实现比原逻辑更健壮
📖 概要
fix(cmd/start): use absolute executable path for child process · 修复以相对路径或通过 PATH 启动时,守护子进程拉起失败的问题。
核心改动:改用 os.Executable() 取绝对路径,重建子进程参数,并对 --force-bin-dir 做去重。
🧭 整体方案
原实现直接用 os.Args[0] 作为 exec.Cmd.Path,当程序通过 ./openlist 或 PATH 查找启动时,os.Args[0] 可能是相对路径或裸命令名,子进程会因工作目录变化而找不到可执行文件。改用 os.Executable() 是 Go 中处理这一问题的标准做法,方案正确。
📊 变更统计
1 个文件(+17 / -7 行) | 功能 ⭐⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐⭐ | 前向兼容 ⭐⭐⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐⭐
🚨 关键问题
P0(阻塞合并):无
P1(建议修复):无
P2(可选):
- 💡 原实现用
args[1] = "server"原地修改os.Args,属于会污染全局状态的写法;新实现改为append([]string{"server"}, os.Args[2:]...)构造新切片,这个改进很好~ 顺带一提,新写法隐含了「os.Args至少有 2 个元素」的前提,考虑到该函数由start子命令触发时必然满足,实际不会越界,仅作记录。 - 💡
--force-bin-dir去重同时匹配了--force-bin-dir与--force-bin-dir=两种形式,考虑周到。若想更简洁,也可以用slices.ContainsFunc~
📂 逐文件分析
cmd/start.go
改动意图:确保守护模式下子进程能被可靠拉起。
代码逻辑:os.Executable() 解析绝对路径 → 构造 ["server", <原始参数>...] → 检查并按需追加 --force-bin-dir → exec.Command 启动。
问题分析:逻辑正确,且顺带修复了原代码重复追加 --force-bin-dir 的潜在问题。os.Executable() 失败时 log.Fatal 退出也是合理的——这种情况下无法安全继续。
详细建议:无需改动。
✅ 待处理清单
- 在 Linux / Windows 下分别验证
openlist start守护模式正常拉起 - 确认通过符号链接启动时行为符合预期(
os.Executable()在部分平台会解析软链)
🎯 结论:✅ 建议 Approve — 标准做法修复真实问题,改动干净,无阻塞项。
…istTeam#2125) * fix(cmd/start): use absolute executable path for child process * fix(cmd/start): detect force-bin-dir flag variants --------- Co-authored-by: Zoe Lee <zoelee@gmail.com>
Description / 描述
start命令启动子进程时使用的路径从os.Args[0]改为os.Executable()。start后的用户参数(os.Args[2:])给server。--force-bin-dir时不再重复追加。Motivation and Context / 背景
在 Windows 上,当添加了可执行文件目录环境变量后,从非可执行文件目录调用
openlist start时,os.Args[0]可能是相对路径(如.\openlist),导致子进程启动失败:exec: ".\\openlist": executable file not found in %PATH%。How Has This Been Tested? / 测试
在非可执行文件目录执行
openlist start,确认不再出现exec: ".\\openlist": executable file not found in %PATH%,确认start能成功拉起子进程(日志显示success start pid)。Checklist / 检查清单
我已阅读 CONTRIBUTING 文档。
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已相应更新了相关仓库(若适用)。