On 6/22/20 4:48 PM, Godmar Back wrote: > (Disclosure: I performed a search for terminal, terminal settings, > tcsetattr in the bash-bug mailing list, without finding a discussion. > My apologies if this is a known issue or was already discussed.) > > Hi, > > according to POSIX Part A, Base Definitions (line 726-728, pg 20, Part > A: Base Definitions-IEEE and The Open Group.), a job control shell has > the following responsibility: > > "When a foreground (not background) job stops, the shell must sample > and remember the current terminal settings so that it can restore them > later when it continues the stopped job in the foreground (via the > tcgetattr( ) and tcsetattr( ) functions)." > > Does bash implement this functionality? If implemented correctly, I > would expect the program appended below to not fail its assertions.
Nobody does this. What job control shells do is to save the tty state after a program's successful termination and use that saved state to restore the tty settings after a program stops or terminates due to a signal. > However, it fails - tested with bash 4.4 on CentOS 8 using a pty > created by sshd. > I also looked at the bash 5.0 source code and could not spot where > bash implements this. You can look at get_tty_state() and set_tty_state() in jobs.c. > I first noticed this when students in my class's shell project failed > to properly implement terminal handling, but programs such vi/vim > still continued to work even when stopped and later placed back in the > foreground. I discovered that these programs implement a SIGCONT > handler where they restore their terminal state when continued, but I > wrote this off as an attempt to be robust in the presence of buggy > shells. This is how programs that modify terminal settings, like editors or more/less pagers, do things. It's standard behavior. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/