I have implemented the term changes almost as planned: > * Copy the discard-output flag from the FLUSHO bit of > termios::c_lflag, when TIOCSETA, TIOCSETAW, or TIOCSETAF is > used. This is term/users.c (set_state), I believe. The GNU C > Library already defines FLUSHO in both <bits/ioctls.h> and > <bits/termios.h>. It was easier to delete the FLUSH_OUTPUT flag altogether and make everything use the FLUSHO flag of termstate.c_lflag instead. That way, the discard-output flag doesn't have to be separately copied. This change alone causes the discard-output flag to be cleared in each new ssh session, and when bash is about to display its prompt. It's definitely an improvement. > * Clear the discard-output flag when TIOCSTART is used. > This is term/users.c (S_tioctl_tiocstart), I believe. Right, S_tioctl_tiocstart should clear FLUSHO, like it clears USER_OUTPUT_SUSP except in a different variable. I didn't test this part though. > * Clear the discard-output flag when the user types almost any > other character, like the glibc documentation said. That was the hardest part. input_character should clear FLUSHO on any character, unless: (1) the character is the DISCARD character and it caused FLUSHO to be set during the current call; or (2) the character is the STOP character and it caused USER_OUTPUT_SUSP to be set during the current call; or (3) USER_OUTPUT_SUSP was already set on entry, and was not cleared during the current call because the character is not the START character and the IXANY mode is not set. I implemented those at the end of input_character. The code detects (1) by checking whether FLUSHO is clear in the lflag variable, which was copied from termstate.c_lflag at the beginning of input_character. Also, if input_character clears FLUSHO during the current call, then any previously set FLUSHO must not prevent the current character from being echoed. I implemented that by making echo_char clear FLUSHO unconditionally. (This is similar to what NetBSD does, except they also have some weird flag for tabs.) echo_char is called only from within input_character (possibly via reprint_line or erase_l), so the user must have typed something if echo_char is called; and it is not called in the cases (1)(2)(3) listed above. (Arguably, it should be called in case (1), but that is no problem if FLUSHO is set after the call rather than before.) If echoing is disabled, then echo_char is not called so FLUSHO may remain set longer than usual, but it will be cleared at the end of input_character anyway. A Hurd developer advised me not to post the patches themselves because I don't intend to assign copyright to the FSF. The diffstat (not counting the "prominent notices") is 18 insertions and 7 deletions, and the FSF considers "around 15 lines of code" the limit for a "tiny change".
Attachment:
pgpbYpA9ngII8.pgp
Description: PGP signature