tmux 3.6b: "open terminal failed: not a terminal" on Linux — caused by brew ncurses 6.6
upstream issue
## `brew config` AND `brew doctor` output
```
HOMEBREW_VERSION: 5.1.13
ORIGIN: https://github.com/Homebrew/brew
HEAD: d8deaca5574faf79a27f110caedc9e153709e628
Last commit: 3 days ago
Branch: stable
Core tap JSON: 24 May 13:08 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 4.0.5
CPU: quad-core 64-bit
Git: 2.54.0
Curl: 8.5.0
Kernel: Linux 6.8.0-107-generic x86_64 GNU/Linux
OS: Ubuntu 24.04.4 LTS (noble)
Host glibc: 2.39
brew doctor: Your system is ready to brew.
```
## What were you trying to do (and why)?
Attach to an existing tmux session via `tmux attach -t <name>` — the most basic tmux operation.
## What happened (include all command output)?
After `brew install tmux` (installs 3.6b), **every `tmux attach` fails** in multiple common environments:
- Interactive SSH shell (`ssh user@host`, then `tmux a`)
- VS Code Remote integrated terminal
- `script`-created PTY
```
$ tmux new -d -s test
$ tmux a -t test
open terminal failed: not a terminal
```
The **only** environment where attach works is `ssh -t host "tmux a -t test"` (forced PTY with terminal size forwarding).
### Root cause: brew's ncurses 6.6
The brew tmux binary links against brew's `ncurses 6.6` (`/home/linuxbrew/.linuxbrew/opt/ncurses/lib/libncursesw.so.6`). The tmux server receives the client's PTY fd via `SCM_RIGHTS`, then calls `tty_init()` → ncurses `setupterm()`. Brew's ncurses 6.6 rejects certain valid PTY devices that the system ncurses (6.4) accepts.
**Proof — same binary, different libraries:**
```sh
# Fails: brew tmux + brew ncurses
script -qc 'tmux new -d -s x && tmux a -t x' /dev/null
# → open terminal failed: not a terminal
# Works: brew tmux + system ncurses
script -qc 'LD_LIBRARY_PATH=/lib/x86_64-linux-gnu tmux new -d -s y && tmux a -t y' /dev/null
# → attaches successfully
# Works: system tmux 3.4 + system ncurses
script -qc '/usr/bin/tmux -S /tmp/t34 new -d -s z && /usr/bin/tmux -S /tmp/t34 a -t z' /dev/null
# → attaches successfully
```
`strace` confirms the tmux server's `tty_init()` path fails, causing `CLIENT_TERMINAL` flag to not be set — the tmux source code for this check is identical between 3.4 and 3.6b, so the behavioral difference is entirely from the linked ncurses library.
## What did you expect to happen?
`tmux attach` should work in an interactive SSH session and VS Code terminals, same as the system-packaged `tmux 3.4` and same as `brew tmux` with system libraries.
## Step-by-step reproduction instructions
```sh
# 1. Install tmux via brew on Linux (Ubuntu 24.04)
brew install tmux
# 2. Verify brew tmux is first in PATH
which tmux
# → /home/linuxbrew/.linuxbrew/bin/tmux
# 3. Reproduce (script simulates a PTY environment like SSH/VSCode)
script -qc 'tmux new -d -s repro && tmux a -t repro; echo "exit=$?"' /dev/null
# → open terminal failed: not a terminal
# → exit=1
# 4. Confirm it's the linked ncurses — same binary, system libs → works
script -qc 'LD_LIBRARY_PATH=/lib/x86_64-linux-gnu tmux new -d -s repro2 && tmux a -t repro2 -d; echo "exit=$?"' /dev/null
# → exit=0 (success)
# 5. Cleanup
tmux kill-server 2>/dev/null
LD_LIBRARY_PATH=/lib/x86_64-linux-gnu tmux kill-server 2>/dev/null
```
## Environment
| Component | Version |
|-----------|---------|
| OS | Ubuntu 24.04.4 LTS |
| Kernel | 6.8.0-107-generic |
| Homebrew | 5.1.13 |
| brew tmux | 3.6b |
| brew ncurses | 6.6 |
| system tmux | 3.4-1ubuntu0.1 |
| system ncurses | 6.4+20240113 |
## Suggested fix
The tmux formula could either:
- Link against the system ncurses (`uses_from_macos "ncurses"` already exists for macOS — add equivalent Linux handling), or
- Pin ncurses to a version that doesn't exhibit this regression
3 条评论