Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: Does bash save/restore terminal settings as required by POSIX job control? Date: Mon, 22 Jun 2020 18:28:07 -0400 Organization: ITS, Case Western Reserve University Lines: 59 Approved: bug-bash@gnu.org Message-ID: References: <47f62134-eab7-b5e3-3448-2b7bb9c93444@case.edu> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1592864898 26268 209.51.188.17 (22 Jun 2020 22:28:18 GMT) X-Complaints-To: action@cs.stanford.edu Cc: chet.ramey@case.edu, bug-bash@gnu.org To: Godmar Back Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1592864892; bh=rqHPDhDpHsrUaZRxMfsN3sPHXvGbvHp4etZU0VsO/qQ=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=EN2HP2UUdYLR6DXKMMEvhDC0jCS1Mr4etcbPSUGQQAhjGfDz0rAhpSjuz+frWIu+4M jEnz6QTxGIvqgUYjzgzguHppGhHpvw4D0OPiWDJfV7QubXCogf/yC178pcbYwlAq23u NZTbtc48gR41/BWGlxBEsXzhovFBb7dXX4DfzInTwGmO86KfQPzTNZvBZ1pKFlJiEVG Dx5tLRiDecDOe5X1Ef9MKk5GfgoSJwqI7wt/Ya4t6dkR8gX1TfA+4bCE+KqcaCMGUsJ QC7bpWWs2++HfPhhQfPczPOMVUXkIuKhNpuzkEQr1mAFpNua1hIm/6ANCyEB3QsKvhf I/16k2tA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1592864890; bh=wpJOhl2FEaFKFE+kU6H/PGp+FaEf4Tlw2yD2aHVrfuU=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=2jufCLi03X6mpwNHHKpmPHSXu3G4K614sVYAxUV7b7G4C6ZWl+F1aWa8xGn0T26G84 RiNWSzPCA4ivv0cPHmZaFgxnx75o+6PeSqj0ZaB01PQLtxerBZysGJT/G8k3LOESba8 FBYcn33+qc0U/ZlGWeRN5m7qJ7EHG5K9UdBdIs5ShS4F19StN2L9ogZ8PsPztHR4XR7 ud6o0lNPgwWTl8nxHBclcqBFmno7NTU5AQkv6PwZV89cJ/gUxK1zBVmkc57V/c7IVRx 6+2mHXTwxfuGfRDmSwB4zcuk0ZfSOwdMZaG1hTNA/mQShjy+3EDzYQLqOP+s2nw3vqd Sm8QIcGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=reply-to:cc:subject:to:references:from:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=wpJOhl2FEaFKFE+kU6H/PGp+FaEf4Tlw2yD2aHVrfuU=; b=LRxbg8rep044zzC5Kjk2Givl9a52g4kEb6cBLChwk8/1j9FYggR4+ZUB6eQJLqLJKE tbayyrxYNt/aQSoX3XC0USbfstXsGopnZ4GlO3p80RHfq2EFcw/iuVEx/+nhRvZxjEdh 1o6kIQYOtDwbLIuFq5ZZEvrw2g9/NyDSkZcWmk68uT6SSprleMcZb41hyv4DKqw3TXHl xVs9kHWeNJRhjla+dbThkI5+1fml0nI/VgjZf2ldbwvO0f9Q/1xfyud4wcjhctXup7NJ WpnLeSj7n/VqGdd7NPZ5bzuiLje/C1q/Svn3NwKLv6u3sUWVPq6vtIrdd5uB66j+T99x 8pFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:cc:subject:to:references:from:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=wpJOhl2FEaFKFE+kU6H/PGp+FaEf4Tlw2yD2aHVrfuU=; b=HpnbmgfLoxEFZWEzlAC4591mjroV/BRSFbQ7vABKyY9STjI4BSn9fVpz8/Go7V5JoV zL0BtL+0UAnhpcb/z+vEj6yG8wSOhwE4rnW8h59VDjwHx9QSZPy1JHYNXQK4bEMbtCwZ paeCvzqTnntluh10opop5SSxiwM4hB6Zot7cA8rkKuAGgDxBgexZwGhG5q+iGpFk+rfl YKQIkXcT4ngxjIkuioYwDySULR3j1sJxMDFrRIMyILdpNzPQ2b9bKY08JFvee1Sywlzo j3TnKGB8LjES7S1bTyHSXd99ngfgKBCXjDEjyxBm9scLTwwF2vh3mXjlIr+2sWmo8Cku /KHw== X-Gm-Message-State: AOAM530gHgkKYNvIIMyHentJViumfdTyBh+0AKvHurfcTqv4OZB1nG3C XnNP7wBwZJWHdYw+GQeu5CHpogqGGXr3t1TwGYwteeFVbrto7XV82G2a+kbl1wQ8CxNs4YvQc2F Za+9UCd3LFtw= X-Received: by 2002:a02:a104:: with SMTP id f4mr6830474jag.88.1592864889984; Mon, 22 Jun 2020 15:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz16X0LiaUlLFNvxSQUKlP635D0CO/AaMQaQ1anVtECiraCC2JOAHYUd+l4aFfz9wgUvKBr7w== X-Received: by 2002:a02:a104:: with SMTP id f4mr6830436jag.88.1592864889616; Mon, 22 Jun 2020 15:28:09 -0700 (PDT) Autocrypt: addr=chet.ramey@case.edu; prefer-encrypt=mutual; keydata= mQGiBEEOsGwRBACFa0A1oa71HSZLWxAx0svXzhOZNQZOzqHmSuGOG92jIpQpr8DpvgRh40Yp AwdcXb8QG1J5yGAKeevNE1zCFaA725vGSdHUyypHouV0xoWwukYO6qlyyX+2BZU+okBUqoWQ koWxiYaCSfzB2Ln7pmdys1fJhcgBKf3VjWCjd2XJTwCgoFJOwyBFJdugjfwjSoRSwDOIMf0D /iQKqlWhIO1LGpMrGX0il0/x4zj0NAcSwAk7LaPZbN4UPjn5pqGEHBlf1+xDDQCkAoZ/VqES GZragl4VqJfxBr29Ag0UDvNbUbXoxQsARdero1M8GiAIRc50hj7HXFoERwenbNDJL86GPLAQ OTGOCa4W2o29nFfFjQrsrrYHzVtyA/9oyKvTeEMJ7NA3VJdWcmn7gOu0FxEmSNhSoV1T4vP2 1Wf7f5niCCRKQLNyUy0wEApQi4tSysdz+AbgAc0b/bHYVzIf2uO2lIEZQNNt+3g2bmXgloWm W5fsm/di50Gm1l1Na63d3RZ00SeFQos6WEwLUHEB0yp6KXluXLLIZitEJLQwQ2hldCBSYW1l eSAoQ2FzZSBzdGFuZGFyZCkgPGNoZXQucmFtZXlAY2FzZS5lZHU+iF8EExECAB8FAkPi19EC GwMHCwkIBwMCAQMVAgMDFgIBAh4BAheAAAoJELtYafBk6nSrelkAn31Gsuib7GcCZHbv5L5t VKYR9LklAJ4hzUHKA49Z0QXR+qCb80osIcmPSbkBDQRBDrBvEAQAkK6TAOKBEM+EC4j6V/7o /riVZqcgU5cid2qG9TXdwNtD9a3kvA/ObZBO93sX59wc6Bnwo4VJxsOmMlpGrAjJsxNwg3QH akEtf8LXRbVpj5xStdmBdQZUhIQyalo/2/TZq5OijtddUQcL5cs70hTv/FpT3wUvr2Xr8rjF 41IFEz8AAwcD/A0CZEGlzIrT5WCBnl6xBog/8vKiUCbarByat3d1mL6DbizvKNXQRTC9E/vE dENAWCQCjr75Bu55xT8n3SXGtWdDC5xmZ/P3OBYORP8yl8H8I1FIosWOFirbIeYdZPq8SPD1 HL+EXo9zSiHVrrZRJ19ooCKKbSdXHFCY+aJG+0KZiEkEGBECAAkFAkEOsG8CGwwACgkQu1hp 8GTqdKvjcACfZlkVCDwaz/NTO9cy3t69oWpVPNwAnRwe0qk/WL/gfhH346xh5B3HFbFN User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 In-Reply-To: Content-Language: en-US X-Mirapoint-IP-Reputation: reputation=Good-1, source=Queried, refid=tid=0001.0A020301.5EF12F0B.0032, actions=tag X-Mirapoint-IP-Reputation: reputation=good-1, source=Fixed, refid=n/a, actions=tag X-Junkmail-Status: score=8/80, host=mpv3-2015.case.edu X-Junkmail-PrAS-Raw: score=8/80, refid=2.7.2:2020.6.22.215117:17:8.317, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __MULTIPLE_RCPTS_CC_X2, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __URI_NO_WWW, __FRAUD_INTRO, __CP_URI_IN_BODY, __INVOICE_MULTILINGUAL, __CP_NOT_1, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODYTEXTP_SIZE_3000_LESS, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 Received-SPF: pass client-ip=129.22.103.194; envelope-from=chet.ramey@case.edu; helo=mpv3-2015.case.edu X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 17:19:50 X-ACL-Warn: Detected OS = Linux 2.4.x-2.6.x [generic] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: <47f62134-eab7-b5e3-3448-2b7bb9c93444@case.edu> X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:16440 On 6/22/20 5:51 PM, Godmar Back wrote: > 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 assume it's a convention. Bash has done it for forever. >>> 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. I'm not sure that's the reason. It's more likely that no historical shells ever implemented this behavior, and the standard way to write programs that manipulated the terminal settings was to manage them yourself. You either caught SIGTSTP and did the restore/reset tty stuff from the signal handler or you mapped the functionality to a keystroke and did the same thing from a function where you sent yourself SIGSTOP. Editors and other programs have been `compensating' in this way since before there was POSIX. Look at the 4.3 BSD source for `more' or `vi', for example. > > 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? ksh93u+ 2012-08-01 on RHEL 7 does do this. tcsh isn't a POSIX shell, so I admit I don't pay attention to it. I got curious, so I looked at what dash does -- a system call trace looks like it seems to `succeed' because it doesn't save or restore the terminal settings at all (dash-0.5.10.2). That presumably holds true for other ash- based shells, but I didn't check. It does leave them susceptible to programs that don't clean up the terminal when they're suspended or terminate abnormally. Chet -- ``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/