[PATCH v2] util: Flush cursor state to stdout before removing signal handler

Allan McRae allan at archlinux.org
Fri Jul 22 00:21:31 UTC 2022


On 6/4/22 14:14, Chris Down wrote:
> It's possible that the cursor does not reappear after pressing ^C during
> shutdown. In my case, I noticed this when pressing ^C after getting
> results from `pacman -F` -- this can reasonably reliably be triggered by
> issuing a file query and pressing ^C shortly after results are shown.
> 
> There are two reasons for this issue:
> 
> 1. The graceful SIGINT handler is removed at the start of cleanup(), but
>     the window from entering cleanup() to reaching exit() is non trivial.
>     The main offender is FREELIST(pm_targets), which on my T14s takes
>     >0.1s to execute. This means that if you are unlucky enough to press
>     ^C while there, the cursor isn't coming back, because we haven't
>     issued any command to show the cursor again yet, and the userspace
>     signal handler is already blown away.
> 2. Moving console_cursor_show() to earlier in cleanup() only half solves
>     the issue. While it's fine not to flush after _hiding_ the cursor,
>     since it will at least make itself apparent before any other text
>     reaches the screen, _showing_ the cursor must be followed by flushing
>     stdout, because once the graceful SIGINT handler is gone, if you
>     press ^C, no flush will be triggered (and thus there will be no
>     cursor).
> 
> This fixes the issue by always starting out by showing the cursor again
> at cleanup() time. This means that no matter where we get caught at ^C,
> we will not end up leaving the terminal without its beloved ensign.
> 
> Signed-off-by: Chris Down <chris at chrisdown.name>
> ---

Applied.

Thanks,
Allan


More information about the pacman-dev mailing list