[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does bash save/restore terminal settings as required by POSIX job co

From: Chet Ramey
Subject: Re: Does bash save/restore terminal settings as required by POSIX job control?
Date: Mon, 22 Jun 2020 17:19:46 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

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

> 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    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]