Skip to content

Commit 2d01916

Browse files
lroolleclaude
andcommitted
fix(tmux): portable port probe, verify remote socket, doctor quoting
- deva.sh tmux setup/doctor: stock macOS has no coreutils timeout — probe port 22 with nc (present there), /dev/tcp fallback - deva-tmux bridge (ssh): verify the remote tmux socket exists before forwarding — a tunnel to a missing socket reports up and then fails opaquely on every connection - deva-tmux doctor: session count through the same sh -c positional pattern as every other remote invocation Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 0d2d173 commit 2d01916

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

deva.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,16 @@ shorten_path() {
13091309
# provisioning). The host side owns exactly what must not be done from
13101310
# inside the sandbox: authorizing the ssh key and running the socat daemon.
13111311
1312+
# Stock macOS ships no `timeout`; probe with nc (present there) and fall
1313+
# back to /dev/tcp, which fails fast on a refused localhost connect.
1314+
tmux_host_port22_open() {
1315+
if command -v nc >/dev/null 2>&1; then
1316+
nc -z -w 2 127.0.0.1 22 2>/dev/null
1317+
else
1318+
(exec 3<>/dev/tcp/127.0.0.1/22) 2>/dev/null
1319+
fi
1320+
}
1321+
13121322
tmux_host_setup() {
13131323
local marker="deva-host-tmux"
13141324
local pub=""
@@ -1335,7 +1345,7 @@ tmux_host_setup() {
13351345
echo "undo: remove the '$marker' line from ~/.ssh/authorized_keys"
13361346
fi
13371347
1338-
if timeout 3 bash -c 'exec 3<>/dev/tcp/127.0.0.1/22' 2>/dev/null; then
1348+
if tmux_host_port22_open; then
13391349
echo "ok: sshd is listening on port 22"
13401350
else
13411351
echo "warning: sshd is not reachable on 127.0.0.1:22" >&2
@@ -1435,7 +1445,7 @@ tmux_host_doctor() {
14351445
else
14361446
echo "ssh keypair: NONE (ssh-keygen -t ed25519)"
14371447
fi
1438-
if timeout 3 bash -c 'exec 3<>/dev/tcp/127.0.0.1/22' 2>/dev/null; then
1448+
if tmux_host_port22_open; then
14391449
echo "sshd port 22: open"
14401450
else
14411451
echo "sshd port 22: CLOSED (macOS: Sharing > Remote Login)"

scripts/deva-tmux

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ bridge_start() {
259259
bin=$(host_tmux_bin)
260260
remote_sock=$(host_tmux_socket "$bin")
261261
[[ -n "$remote_sock" ]] || die "cannot determine host tmux socket path"
262+
# Forwarding to a missing remote socket "succeeds" and then every
263+
# connection through it fails opaquely — verify the server first.
264+
hssh "$(host_target)" "sh -c 'test -S \"\$0\"' $(printf '%q' "$remote_sock")" ||
265+
die "no host tmux server socket at $remote_sock — start one on the host: tmux new -d"
262266
if [[ "$foreground" == true ]]; then
263267
echo "bridge (ssh, foreground): $BRIDGE_SOCK -> $(host_target):$remote_sock"
264268
exec ssh -o BatchMode=yes "${SSH_OPTS[@]}" -N -L "$BRIDGE_SOCK:$remote_sock" "$(host_target)"
@@ -389,7 +393,7 @@ cmd_doctor() {
389393
local bin
390394
if bin=$(host_tmux_bin 2>/dev/null); then
391395
echo "host tmux: $bin"
392-
echo "host sessions: $(hssh "$target" "$bin ls 2>/dev/null | wc -l" | tr -d ' ')"
396+
echo "host sessions: $(hssh "$target" "sh -c '\"\$0\" ls 2>/dev/null | wc -l' $(printf '%q' "$bin")" | tr -d ' ')"
393397
else
394398
echo "host tmux: NOT FOUND on host"
395399
fi

0 commit comments

Comments
 (0)