Skip to content

修复 #632:zsh 下 service_is_active 误报导致 clashctl ui 端口随机重分配 - #633

Merged
nelvko merged 2 commits into
nelvko:masterfrom
Vriessss:master
Oct 16, 2026
Merged

nelvko merged 2 commits into
nelvko:masterfrom
Vriessss:master

Conversation

@Vriessss

Copy link
Copy Markdown
Contributor

问题

zsh 无法求值服务层使用的 Bash 专有构造(read -r -a、${!arr[@]}、${s:i:1}、$BASHPID、$BASH_SOURCE)。在 zsh 下,service_is_active 会在内核仍在运行时报告 false,导致 _detect_ext_addr 将其自身的 external-controller 端口视为外部冲突,并在每次 clashctl ui 运行时重新分配随机端口,使打印出的地址与正在运行的内核不同步,用户不得不反复修改 URL。

变更

  • 新增 scripts/lib/shell.sh,其中包含一个 bash -c 转发器。
  • 从 dispatcher 中将所有不会修改 shell 状态的子命令都通过该转发器执行。
  • 将 on/off/update/help/version 保留在当前 shell 中执行。
  • 将各命令中重复的 ZSH_VERSION 防护合并到共享 helper 中。
  • 扩展 tests/zsh-commands.sh,以断言转发契约。

Fixes #632

Zsh cannot evaluate the Bash-only constructs used by the service layers
(read -r -a, ${!arr[@]}, ${s:i:1}, $BASHPID, $BASH_SOURCE). Under zsh,
service_is_active reported false while the kernel was still running, so
_detect_ext_addr treated its own external-controller port as a foreign
conflict and reassigned a random port on every clashctl ui run, leaving the
printed address out of sync with the live kernel and forcing users to change
the URL repeatedly.

Add scripts/lib/shell.sh with one bash -c forwarder, route every
non-shell-mutating subcommand through it from the dispatcher, and keep
on/off/update/help/version in the current shell. Fold the duplicated
per-command ZSH_VERSION guards into the shared helper and extend
tests/zsh-commands.sh to assert the forwarding contract.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

将服务和控制地址替身写入测试安装目录,确保 zsh 转发后的 Bash 子进程也能重新加载。固定测试服务管理方式为 nohup,避免宿主机已有的 systemd 服务掩盖替身失效。
@nelvko
nelvko merged commit 5807dc3 into nelvko:master Oct 16, 2026
2 checks passed
@nelvko

nelvko commented Oct 16, 2026

Copy link
Copy Markdown
Owner

感谢修复!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] zsh环境下部分命令失效,无法正常调用

2 participants