Skip to content

[Kernel/POSIX] Distinguish terminals from character devices - #1104

Open
brandonpayton wants to merge 1 commit into
mainfrom
kernel/posix-terminal-ofd-classification-main
Open

[Kernel/POSIX] Distinguish terminals from character devices#1104
brandonpayton wants to merge 1 commit into
mainfrom
kernel/posix-terminal-ofd-classification-main

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

Why

Kandelo used the broad character-device file type for both interactive terminals and virtual devices such as /dev/null, framebuffer, audio, and DRM. Terminal checks therefore treated all of those devices as interactive. For example, musl implements isatty() with TIOCGWINSZ, so a program writing to /dev/null could incorrectly change its behavior as though output were attached to a terminal.

What changed

  • Add one terminal classifier owned by the open file description.
  • Treat PTY masters and slaves as terminals.
  • Treat legacy host stdio as a terminal only when its canonical stdio path and host handle agree.
  • Use the same classification for isatty, termios calls, terminal ioctl gating, and fpathconf.
  • Keep generic FION requests and device-specific framebuffer, audio, and DRM ioctls on their existing paths.
  • Cover captured and terminal stdio, PTY endpoints, redirection, every virtual character device, a future positive-handle nonterminal device, and the exact TIOCGWINSZ request used by musl.

ABI

No ABI bump is needed. This corrects syscall semantics without changing syscall numbers, marshalling, exported signatures, structure layouts, generated bindings, or VFS ABI metadata. Existing ABI 42 programs and bottles remain valid.

Validation

  • Focused virtual-character-device terminal matrix: 1 passed
  • Full canonical kernel unit suite: 1,253 passed, 0 failed
  • ABI snapshot, C header, and TypeScript bindings: current
  • git diff --check: passed

Not run

The vendored libc, POSIX, and Sortix suites do not currently contain matching terminal/isatty cases. Product-level Node and Chromium Homebrew validation is running in the parent migration workstream.

Character-special mode is broader than terminal identity. Kandelo encoded host terminal stdio and virtual devices such as /dev/null, framebuffer, audio, and DRM with FileType::CharDevice, so terminal probes could mistake every virtual character device for an interactive terminal. In particular, musl implements isatty() with TIOCGWINSZ, causing redirected Bash output to observe false terminal behavior.

Derive terminal identity from the open file description: dedicated PTY master/slave types are terminals, and legacy host stdio is a terminal only when its stable canonical stdio path and host handle agree. Reuse that classification across isatty, termios, ioctl namespace gating, and fpathconf. Keep generic FION* requests ahead of terminal gating and preserve device-specific ioctl dispatch.

This is a compatible semantic correction under ABI 42. It changes no syscall numbers, marshalling, exported signatures, structure layouts, generated bindings, or VFS ABI metadata, so existing binaries remain valid and need no rebuild.

Validation:
- focused non-terminal character-device terminal matrix, including the exact musl TIOCGWINSZ isatty path: 1 passed
- full kernel unit suite: 1,253 passed
- ABI snapshot and generated bindings check
- git diff --check
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.

1 participant