Skip to content

Keep a file descriptor open for reserved VTs - #476

Open
Mrmaxmeier wants to merge 1 commit into
ubuntu:mainfrom
Mrmaxmeier:hold-fd-for-vts
Open

Keep a file descriptor open for reserved VTs#476
Mrmaxmeier wants to merge 1 commit into
ubuntu:mainfrom
Mrmaxmeier:hold-fd-for-vts

Conversation

@Mrmaxmeier

Copy link
Copy Markdown

Hi,

I recently looked into odd behaviour with LightDM on NixOS:
NixOS/nixpkgs#422331 (comment)
NixOS sets minimum-vt = 1 and suffers from a race where a VT is used both by the desktop session and getty. In this situation, getty then receives desktop session keystrokes and resets the keyboard out of K_OFF. As a symptom, Alt+Left/Right then switch VTs from inside of the desktop session.

It seems like this can be mitigated by holding onto VT fds inside of LightDM: logind skips VTs that are "in use" / where fds are held by any process.

Note: This change in LightDM is LLM-suggested but looks fine to me. I'm running the patched version and while the underlying mechanism to avoid collisions doesn't seem fully sound to me, it seems to mitigate the racy behaviour.

Does this change make sense or is NixOS holding display managers wrong in this case?

Thanks! 🙂

logind decides whether to spawn an autovt getty on a VT by asking the
kernel whether anything currently has it open (vt_is_busy(), consulted
from manager_spawn_autovt() on every VT switch). The VT we pick becomes
active before the display server running on it has opened it, so logind
can win that race and start a getty on the VT we are about to use.

The getty then shares the VT with the session and keeps resetting the
keyboard out of the K_OFF mode the session controller asks for, so that
Alt+Left and Alt+Right switch VT from inside the session.

Hold a file descriptor on each VT for as long as we have it reserved, so
the kernel reports it as busy for as long as it is ours.

This only has an effect on VTs logind would spawn a getty on: those up to
NAutoVTs (6 by default) and other than ReserveVT. With the default
minimum-vt of 7 lightdm is outside that range and nothing changes; it
matters for configurations that lower minimum-vt.

Assisted-By: Claude Opus 5 <noreply@anthropic.com>
@jpeisach

jpeisach commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Does this change make sense or is NixOS holding display managers wrong in this case?

/shrug

I'll come back to this.. eventually! :D

Thanks for disclosing your LLM usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants