Page MenuHomeFreeBSD

pty: preserve O_NONBLOCK when opening /dev/ptmx
ClosedPublic

Authored by vova_fbsd.ru on Tue, Oct 13, 2:48 PM.
Tags
None
Referenced Files
F176322227: D60700.diff
Sat, Oct 17, 10:08 PM
Unknown Object (File)
Fri, Oct 16, 1:02 AM
Unknown Object (File)
Wed, Oct 14, 9:00 AM
Unknown Object (File)
Wed, Oct 14, 7:18 AM
Unknown Object (File)
Wed, Oct 14, 7:09 AM
Unknown Object (File)
Wed, Oct 14, 5:18 AM
Unknown Object (File)
Wed, Oct 14, 5:17 AM
Unknown Object (File)
Wed, Oct 14, 2:53 AM
Subscribers

Details

Summary

ptmx_fdopen() masks the supplied file flags to FREAD | FWRITE before
passing them to pts_alloc(). This discards FNONBLOCK even when the
caller explicitly requests O_NONBLOCK.

As a result, open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK) succeeds,
but the returned file is blocking. F_GETFL reports O_NONBLOCK cleared,
and a subsequent read can block instead of returning EAGAIN when no
data is available.

This causes Linux xfce4-terminal/VTE running under Linuxulator to
freeze. VTE opens the PTY master with O_NONBLOCK and relies on
nonblocking reads while draining terminal output. Once the available
data has been consumed, the main UI thread blocks in ptsdev_read(),
leaving the window unresponsive even though the child shell has
started successfully.

Include FNONBLOCK in the flags passed to pts_alloc(). Blocking opens
retain their existing behavior. No change to posix_openpt(2) flag
validation is required.

The flag loss also reproduces with a native FreeBSD program, so the
problem is in the shared /dev/ptmx implementation rather than Linux
syscall flag translation.

Validation:

  • Before the fix, a native FreeBSD reproducer observes O_NONBLOCK cleared after opening /dev/ptmx with that flag.
  • Explicitly setting O_NONBLOCK with F_SETFL works, confirming that nonblocking PTY operation itself is supported.
  • After the fix, F_GETFL preserves O_NONBLOCK when requested and leaves it cleared for a blocking open.
  • xfce4-terminal in the Linux jail displays the shell prompt and accepts input.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib added a reviewer: markj.
kib added inline comments.
sys/dev/pty/pty.c
132
This revision is now accepted and ready to land.Tue, Oct 13, 3:37 PM
This revision now requires review to proceed.Tue, Oct 13, 4:06 PM
This revision was not accepted when it landed; it landed in state Needs Review.Fri, Oct 16, 1:35 PM
This revision was automatically updated to reflect the committed changes.