Fix exit-status: send SSH_MSG_CHANNEL_REQUEST exit-status per RFC 4254 §6.10
This commit is contained in:
37
AGENTS.md
37
AGENTS.md
@@ -2850,5 +2850,38 @@ chacha20-poly1305@openssh.com
|
||||
|
||||
---
|
||||
|
||||
**最后更新**:2026-06-20 13:45
|
||||
**版本**:1.30(Phase 8.3 Docker 测试完成)
|
||||
---
|
||||
|
||||
## exit-status 修复完成(2026-06-20)⭐⭐⭐⭐⭐
|
||||
|
||||
**背景**:SSH `ssh -p 2024 demo@127.0.0.1 "echo hello"` 返回 `exit status -1`
|
||||
|
||||
**根本原因**(RFC 4254 §6.10):
|
||||
- OpenSSH client 要求 server 在通道关闭前发送 `SSH_MSG_CHANNEL_REQUEST "exit-status"`
|
||||
- `handle_child_exited()` 之前只发送 EOF + CLOSE,从未发送 `exit-status` 请求
|
||||
- 因此 OpenSSH client 不知道子进程的退出码,报告 `exit status -1`
|
||||
|
||||
**修复内容**(`channel.rs`):
|
||||
|
||||
| 修改 | 位置 | 说明 |
|
||||
|------|------|------|
|
||||
| `exit_status: Option<u32>` | `Channel` struct | 存储子进程退出码 |
|
||||
| `channel.exit_status = Some(exit_code)` | `poll_exec_stdout_and_client()` | 在 `child.try_wait()` 返回 status 时保存退出码 |
|
||||
| `build_channel_exit_status()` | 新函数 | 构建 `SSH_MSG_CHANNEL_REQUEST "exit-status" FALSE <code>` |
|
||||
| 发送 exit-status → EOF → CLOSE | `handle_child_exited()` | 按正确顺序发送三个消息 |
|
||||
|
||||
**验证结果**:
|
||||
```bash
|
||||
$ ssh -p 2024 demo@127.0.0.1 "echo hello"
|
||||
hello # ✅ exit status 0 (默认)
|
||||
|
||||
$ ssh -p 2024 demo@127.0.0.1 "exit 42"
|
||||
# 无输出(exit 42 不产生 stdout)
|
||||
$ echo $?
|
||||
42 # ✅ exit status 42 正确传递
|
||||
```
|
||||
|
||||
**累计代码**:5061 行(新增 31 行)
|
||||
|
||||
**最后更新**:2026-06-20 14:15
|
||||
**版本**:1.31(exit-status 修复完成)
|
||||
|
||||
Reference in New Issue
Block a user