Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Godmar Back Newsgroups: gnu.bash.bug Subject: Re: Does bash save/restore terminal settings as required by POSIX job control? Date: Mon, 22 Jun 2020 17:51:30 -0400 Lines: 99 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1592862710 24445 209.51.188.17 (22 Jun 2020 21:51:50 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Chester Ramey Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aqjwmTGVd3mWYXIRwfx7wj8MrwGnBT4k2ODhuc+hh9o=; b=ORlMadXYCK2joINAYx1GCZNGS/8/xpdbiHUZCw0zq98y8dIjl4OAXUnLfGQxlZL0Vs btoMO43zXpigqGaleLlF7gJbOo3loUQblOxxjZBsFMeKKceHL6nk7WgMAFvvXZ5c82si uR72aMTAB2I8G9sjLvIoUscUqr7KQxLh/V6bOLFTmtW4iBHD6mugjhBxL9/JjoO3fEmC Td04iosBWSyyRkMYsB5O9JwSvxhTsaupPYyOXlrbhpx2uLSz0+ZLYon+H+DJ8EJBL4zq 4Z4lwldSEWmTnQhj7rG968v58lmEUTqt4Un8hgvDXf78RMHvZetASpWxtdLI75RB0K2i BIAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aqjwmTGVd3mWYXIRwfx7wj8MrwGnBT4k2ODhuc+hh9o=; b=c1AJlftivctSqsdPhqpadnSGS0PoO+aFLsAC4aKt3EPqaHfQjLbHAtU3ZyThi8XuD3 7wAGBs7o2/yL96TiG0QTrK2YaexN7c5nJCxn/u+kvTxP3HsOldOUKryCPiUx9C3VlFpu VK+yF423UD+msMfWJ0228L4OTC4m9YfUrJh/H4+6/XJlJ0xIyT0chou9N+CGUkgCNsaT y0hyEbLnsPoM+DITgankFdFAPd0caSltDC+mh5PrkAiko8PIdodylGyJTPRz9s5qjodX rEbCgk55pZ1RvLOYc7yLbnYdkUtSOpvX3IyttAJR7uolEVJdxRoL5ScOGAbuQr7j+MFQ oiEQ== X-Gm-Message-State: AOAM5339d4v2TIBkFEaIkzT0444UZSjCSwnSlhuo1hpxH27CcntcKPu9 dfJDdW75wtpFjIQxgWfC0uF9AyVGz5IkaxL7txY= X-Google-Smtp-Source: ABdhPJxvVQWV0kFFghW4HGer6Mv8oyiq14h4co6TyDOZjrPhrOZfINe4t7iT9pYU8xY7LqrqzoIkrwLQBpF7JM8cOOA= X-Received: by 2002:a7b:cd83:: with SMTP id y3mr20153084wmj.5.1592862701585; Mon, 22 Jun 2020 14:51:41 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=godmar@gmail.com; helo=mail-wm1-x32b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:16439 On Mon, Jun 22, 2020 at 5:19 PM Chet Ramey wrote: > > 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. Nobody may be a bit too strong of a statement, though, the version of ksh on CentOS8 does do it, as it passes my test; please observe: $ ksh $ stty -a ... eof = ^D ... $ ./ts_test This job should now stop, please run 'fg' to continue it [1] + Stopped ./ts_test $ stty -a .... eof = ^D; ... $ fg %1 ./ts_test Job now continuing... $ stty -a ... eof = ^E .... $ and also tcsh 6.20.00 I have installed on an Ubuntu 18 box: $ tcsh optiplex:~/tmp> ./ts_test This job should now stop, please run 'fg' to continue it Suspended optiplex:~/tmp> jobs [1] + Suspended ./ts_test optiplex:~/tmp> fg %1 ./ts_test Job now continuing... optiplex:~/tmp> stty -a ... eof = ^E ... and also 'ash' (not sure which version) $ ash $ ./ts_test This job should now stop, please run 'fg' to continue it [1] + Stopped ./ts_test $ fg %1 ./ts_test Job now continuing... $ stty -a ... eof = ^E; $ You are correct that they then preserve the state upon exit. I wasn't aware of that, but it makes a lot of sense - otherwise, "stty sane" wouldn't work, or even be necessary (not necessary if the shell always restored the state it had upon startup.) Out of curiosity, is this a POSIX requirement or an established convention? I can't find it in the POSIX standard quickly. > > > 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. Obviously, if the shells most users use don't implement the POSIX standard, these programs have to compensate. Thank you for your reply. Could you share any insights why bash doesn't follow POSIX in this regard, like zsh, but unlike ksh, tcsh, and dash/ash? I'm genuinely curious. - Godmar