Page MenuHomeFreeBSD

devfs: Keep a Linux controlling tty across the last slave close
Needs ReviewPublic

Authored by vova_fbsd.ru on Tue, Oct 13, 2:50 PM.
Tags
None
Referenced Files
F175978941: D60701.id189728.diff
Wed, Oct 14, 11:47 PM
F175957191: D60701.id189804.diff
Wed, Oct 14, 6:57 PM
Unknown Object (File)
Wed, Oct 14, 10:31 AM
Unknown Object (File)
Wed, Oct 14, 9:46 AM
Unknown Object (File)
Wed, Oct 14, 9:44 AM
Unknown Object (File)
Wed, Oct 14, 8:07 AM
Unknown Object (File)
Wed, Oct 14, 6:19 AM
Unknown Object (File)
Wed, Oct 14, 4:26 AM
Subscribers

Details

Summary

Linux leaves the session's controlling terminal in place after the last file
descriptor on the slave is closed, so a later open of /dev/tty succeeds.
FreeBSD drops the session vnode reference on that close. /dev/tty then fails,
which breaks Linux programs such as xterm that close the pty slave during startup
and expect /dev/tty to keep working.

When the closer is a Linux process, leave the session reference in place.
Still pass FLASTCLOSE to the driver so the master sees hangup.
Native close behavior is unchanged.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 78240
Build 75123: arc lint + arc unit

Event Timeline

Can you provide the self-contained minimal test that I can compile both on FreeBSD and Linux?

sys/fs/devfs/devfs_vnops.c
725–726

If hold_ctty get set to 1, why do we need to ever enter this block?

741

I suggest to handle this differently. Add sv_sysent flag like SV_PERSISTENT_CTTY and test for it there, instead of testing the specific ABI id. Set the flag for all Linux' sysvecs.

In D60701#1391783, @kib wrote:

Can you provide the self-contained minimal test that I can compile both on FreeBSD and Linux?

- usniversal (FreeBSD, Linux) requires libc
- linux binary to build and run on freebsd w/o linux_base

% uname -or
FreeBSD 15.1-RELEASE-p3

% ./ctty-last-close-freebsd
before last close: /dev/tty works, session=81221
FAIL: /dev/tty after last slave close: errno=6 (Device not configured)

% ./ctty-last-close-linux
before last close: /dev/tty works
PASS: /dev/tty still opens after last slave close

devfs: make persistent controlling terminal an ABI property

Add the SV_PERSISTENT_CTTY sysentvec flag for ABIs that retain the
controlling terminal after the last slave descriptor is closed.

Use the flag in devfs_close() instead of checking explicitly for the
Linux ABI, and enable it for all Linux sysentvecs.

This keeps the devfs behavior ABI-agnostic and allows other ABIs to
request the same semantics if needed.

Suggested by: kib
Differential Revision: https://reviews.freebsd.org/D60701

sys/fs/devfs/devfs_vnops.c
725–726

So still: hold_ctty can be calculated before entering this block, it is the property of the p/curproc.
And if the hold_ctty is true, we do nothing under the heavy proc_lock+proctree_lock+session lock + devfs_de_interlock+vnode interlock.

devfs: Avoid ctty teardown locks for persistent ABIs

Determine whether the closing process uses persistent controlling
terminal semantics before entering the ctty teardown path.

Skip the process, proctree, session, devfs, and vnode lock sequence
entirely when SV_PERSISTENT_CTTY is set, since such ABIs do not remove
the session's controlling terminal reference.

The native ctty teardown behavior remains unchanged.

Suggested by:kib
Differential Revision:https://reviews.freebsd.org/D60701