pty-session: defer raw mode until after signals are blocked
ul_pty_setup() switches the user's terminal to raw mode before
ul_pty_signals_setup() blocks signals. A terminating signal delivered
in this window kills the process without reaching ul_pty_cleanup(),
leaving the terminal in raw mode.
Move the raw-mode tcsetattr() out of ul_pty_setup() into a new
ul_pty_terminal_setup() function, to be called after
ul_pty_signals_setup(). This ensures signals are already directed
to signalfd when raw mode is activated, closing the race window.
The setup sequence is now:
ul_pty_setup() -- open pty, save terminal attrs
<app-specific work> -- e.g. utempter (needs SIGCHLD unblocked)
ul_pty_signals_setup() -- block signals, create signalfd
ul_pty_terminal_setup() -- set raw mode (signals already blocked)
fork()
Addresses: https://github.com/util-linux/util-linux/issues/4499 Signed-off-by: Karel Zak <kzak@redhat.com>