Package: tuigreet
Version: 0.9.1-7
Severity: normal
Tags: upstream patch
X-Debbugs-Cc: [email protected], [email protected]
Dear Maintainer,
after a power command (shutdown/reboot from the F12 menu) completes
successfully, tuigreet stalls for 2 seconds and then exits with status 1,
without clearing the screen and without leaving raw mode.
This has the same root cause as #1153617 but is a different call site, and
it is NOT fixed by upstream commit 3e18bcb, which the pending 0.11.1-1 on
Salsa backports as
event-start-terminal-stream-after-terminal-initialization.patch. I am filing
it separately so that it does not get closed together with #1153617.
Root cause
----------
Since ratatui-core 0.1.1, Terminal::clear() saves and restores the cursor:
let original_cursor = self.backend.get_cursor_position()?;
self.clear_viewport()?;
self.backend.set_cursor_position(original_cursor)?;
(ratatui-core 0.1.2, src/terminal/buffers.rs). With the crossterm backend
that writes ESC[6n and waits up to 2000 ms for the reply.
tuigreet calls terminal.clear() in two places. 3e18bcb fixes the one at
startup by creating the crossterm EventStream only after it. The second one
runs after a power command has succeeded (src/main.rs:107 in 0.9.1,
crates/tuigreet/src/main.rs:183 in 0.11.1):
execute!(io::stdout(), LeaveAlternateScreen)?;
terminal.set_cursor_position((1, 1))?;
terminal.clear()?;
execute!(io::stdout(), Hide)?;
disable_raw_mode()?;
At that point the EventStream is necessarily running, so crossterm cannot
hand the ESC[1;1R reply to cursor::position(). The query times out, and the
`?` skips disable_raw_mode() and turns a successful power command into a
failure exit. Unlike the startup case this is not timing dependent.
Reproduction
------------
The 0.9.1-7 binary in sid is linked against crossterm 0.29.0 and
ratatui-core 0.1.2 (crate paths embedded in /usr/bin/tuigreet).
I ran `/usr/bin/tuigreet --power-shutdown true` in a pty whose master side
answers every ESC[6n with ESC[1;1R, with GREETD_SOCK pointing at a listening
socket, then sent F12 and Enter. Three runs out of three:
0.00s DSR #1 answered
1.00s sent F12
2.01s sent Enter
2.02s DSR #2 answered
4.02s exited, status=1, 2.02s after Enter
The same harness against upstream master with the attached change:
0.00s DSR #1 answered
1.01s sent F12
2.01s sent Enter
2.02s exited, status=0, 0.01s after Enter
For a user this is a 2 second hang of the greeter after choosing
shutdown/reboot, with the VT left uncleared and in raw mode, and greetd
seeing its greeter exit with a failure status while the system goes down.
Fix
---
The attached patch clears through the backend, which emits the clear
sequence without querying the cursor. The cursor has just been positioned
explicitly on the line above and the back buffer is irrelevant because the
function returns right after. It is made against upstream 0.11.1 and is meant
to sit next to the 3e18bcb backport in the pending 0.11.1-1; the same
one-line change applies to src/main.rs:107 of 0.9.1.
Thanks for picking the package up.
-- System Information:
Debian Release: forky/sid
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 7.3.4+deb14-amd64 (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
From: Yaroslav Molochko <[email protected]>
Date: Thu, 19 Nov 2026 13:15:11 +0200
Subject: main: clear via the backend after a power command
Since ratatui-core 0.1.1, Terminal::clear() saves and restores the cursor,
which makes the crossterm backend send ESC[6n and wait for the reply. After a
power command has run, the EventStream is live, so cursor::position() never
gets the reply and gives up after 2 seconds. The error is propagated by `?`,
so tuigreet stalls, never clears the screen, skips disable_raw_mode() and
exits with a failure status.
Clear through the backend instead, which does not query the cursor.
Origin: other,
https://github.com/onorua/tuigreet/commit/6c600b039c1c5eba2c87770148f9ff1d4ad18485
Forwarded: no
---
--- a/crates/tuigreet/src/main.rs
+++ b/crates/tuigreet/src/main.rs
@@ -180,7 +180,11 @@
) {
execute!(io::stdout(), LeaveAlternateScreen)?;
terminal.set_cursor_position((1, 1))?;
- terminal.clear()?;
+ // `Terminal::clear()` queries the cursor position (`ESC[6n`) since
+ // ratatui-core 0.1.1. crossterm cannot read the reply while the
+ // `EventStream` reader holds the input lock, so the query times out
+ // after 2 seconds and the error skips the cleanup below.
+ terminal.backend_mut().clear()?;
execute!(io::stdout(), Hide)?;
disable_raw_mode()?;