Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15543
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Chet Ramey <chet.ramey@case.edu> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Signal ignore flags unexpectedly reset after "trap ... EXIT" |
| Date | Wed, 30 Oct 2019 14:50:50 -0400 |
| Organization | ITS, Case Western Reserve University |
| Lines | 150 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.10.1572461464.3687.bug-bash@gnu.org> (permalink) |
| References | <CAOArY3X4VXAkmoCh0vsRZuHsJpw=jOF4_uLocsap1bG+QpK1iQ@mail.gmail.com> <CAOArY3WqmFFT4K4J2uzaEuS3ZcdZ69fwWV5Yj0WcHfr5TAm_qQ@mail.gmail.com> <d3652a9f-f6df-c261-4a1e-6b769dd442bb@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 1572461464 26321 209.51.188.17 (30 Oct 2019 18:51:04 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | chet.ramey@case.edu |
| To | Isaac To <isaac.to@gmail.com>, bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1572461456; bh=vM1X5QoB0fMuInJ4ekmULMl/wvyC8EG3CyvndGFIdv4=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=a73fp7CBYVjHlaOyMsi1n2PgVRm5Xt1+rYcyW35s4Vv+DpzePqQHm56UwdRgqw4lfC 92++IRHlO6U0imXnLb/TfKRIesZOoB7dqeP9DJwgFrIpZ374AL6m5vfY4TOd+vmbjL9 JPky3WjIMsJFM3eYZ/qfUdWw7fxK2FVXdrVIFnRlwQUMlKAIZgS3Ge8C9O4OcqNaMjT ihT75TtZYsBnR4YN724inGvEdag+3q1+VYD0R4IVn2k/p16iDyudJGJwxzmpHd54FuN WcXCoaMjZaSU43tS9Jf5re+sSLFdY00aZsWJEcSR3geD76AwpPC4oWeDxGkamj2iT9o ai37IIUA== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1572461455; bh=P9TgEMGtImJ9xatfEkQFdnb2xmMqB1n3KpJozgY2mv4=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=gO9uSHt+4v8Ovs8o+CcEYypQXaWMBl8Qu2JQfE2Ka83hnMkIRjTBGzNKbk8XkZXVEO lpY9oQJeS8tPb0XTK4SppL3p4r+wV0tVI9iU6SZ0pnmr9roUJww9c0CvmGMMBubX4HZ qKH/nG9O/t8jMDKt8MTm2HowU/KtMMnosSbdCJy5/91EB+mfxCwPh9esbrtEsAmONoq ZyLHwK17s66cMLA3t56fZIRWux9w56DwL4gUuN5Ul8tx4/YX6mMuspasLoafmuBCjRq FZRViA8EJ8NGBnU4UAu4iexMeMzF1JcYFjbvP5odDLGuDjl4L186BkpLVGquJNhG3SN H4RT6+Hw== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=reply-to:cc:subject:to:references:from:openpgp:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=P9TgEMGtImJ9xatfEkQFdnb2xmMqB1n3KpJozgY2mv4=; b=KGz5O1poTvGOjfhtGDN3lylJSGqdos/AORgvnhpXlj5aZuAJ4+mlp3aFP4Hvtm2Np3 P7ng2gXBwoinpJVWtGd/NlZr4nSfWUD5+t/eZJoIcNo5d4NAljDc5xEPG6ftdbL530iz FfkRBiKwW3wkz/5l3Z7ydz3yeuWODyXpNQPYG0i4a9+EKVPBLIOBcSNfLN3U8gh91snP lJfna0y3K5ZfpTdPFA2EtBGaJ3OXL7XMtXOAvhDEFMMIK0f15qnH1ym3gZbT+GvucljE qBZyu6q2lT6Nb1Lc9t5kxNtHCCPerOnankCKt2pfDup01J3MP/ZYRpCx3nyXWA4sN21v KACw== |
| 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:openpgp :autocrypt:organization:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=P9TgEMGtImJ9xatfEkQFdnb2xmMqB1n3KpJozgY2mv4=; b=E01E4FB+nq5bux8JR8Cp1PXRIGtlvb5bhntDCAOy+At96KhOBIb5zXSztLyMZ+Of0Y YSZY908q8qH3EzH5e2K4mOzovaYMenfFOy8wrpUP0NwyXGtxxyxXjrPZlPQipBOBRJc7 KOYTItWQtO3rGBRAjiB0OF6vG3rHYOf4mfcwcytHIFc6d3JuOwpu8xhF1GQWKJ5NKQ+s /yxvW0Jb1VcfosqhIoi31DOGfW8jSqcm1t/r3TNQEGGKdcNPsczvFwyZ+rBgb+MyJ+WB +vYh/LZpwBS/O5xupbBVnIayEWN//B97FOWDT45L5a1msfmZ6qBPVSyrjzcVXGPoaECX m3JQ== |
| X-Gm-Message-State | APjAAAX+7zIl9PakW7AAlNC/HnR4zCJmrt8w5QfzJLzTWXuufsWDOSFe TjvKkb2HjtnWYq+/uETbeehQGrwCYjMzegfYygrlqiLynCiiZOvT1ibE6AYo/2GebbcYKaAu0MD fC5Hng+L4hPI= |
| X-Received | by 2002:a25:4b04:: with SMTP id y4mr671472yba.480.1572461454560; Wed, 30 Oct 2019 11:50:54 -0700 (PDT) |
| X-Google-Smtp-Source | APXvYqw4j/LGhUX1P9xGmj2jhevuYPwV97Fs4wkJk+6zr5psM6tYD3wTe3X//joET27od+ZdJBGn9Q== |
| X-Received | by 2002:a25:4b04:: with SMTP id y4mr671454yba.480.1572461454066; Wed, 30 Oct 2019 11:50:54 -0700 (PDT) |
| Openpgp | preference=signencrypt |
| 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:60.0) Gecko/20100101 Thunderbird/60.9.0 |
| In-Reply-To | <CAOArY3WqmFFT4K4J2uzaEuS3ZcdZ69fwWV5Yj0WcHfr5TAm_qQ@mail.gmail.com> |
| Content-Language | en-US |
| X-Junkmail-Status | score=7/90, host=mpv3-2015.case.edu |
| X-Junkmail-PrAS-Raw | score=7/90, refid=2.7.2:2019.10.30.173916:17:7.944, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __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_CC1, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_WITH_PATH, __URI_NO_WWW, __CP_URI_IN_BODY, __INVOICE_MULTILINGUAL, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODY_SIZE_5000_5999, __MIME_TEXT_P1, __MIME_TEXT_ONLY, __URI_NS, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] |
| X-Received-From | 129.22.103.194 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <d3652a9f-f6df-c261-4a1e-6b769dd442bb@case.edu> |
| X-Mailman-Original-References | <CAOArY3X4VXAkmoCh0vsRZuHsJpw=jOF4_uLocsap1bG+QpK1iQ@mail.gmail.com> <CAOArY3WqmFFT4K4J2uzaEuS3ZcdZ69fwWV5Yj0WcHfr5TAm_qQ@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15543 |
Show key headers only | View raw
On 10/18/19 10:49 AM, Isaac To wrote: > Dear Chet, > > I read your reply in the mailing list archive. Thanks a lot for the > explanation, I get much better ideas about what the shell wants to do for > me after reading it. Sorry that I have to reply to my own message rather > than yours. I'll subscribe to the mailing list to ensure that this is not > needed any more. > > Reading your response carefully I think you get most of the things you say > you didn't get. For others, I want to add one comment: > >> trap '' USR1 >>> grep SigIgn /proc/$BASHPID/status >> >> Presumably this reflects it; I don't know how to interpret the output. >> > > This is a bitmask containing ignored signals, where signal n is represented > by value (1 << (n - 1)). The 200 is signal 10, i.e., USR1. > > Then I want to explain what I consider a bug: > >> ( >>> echo subshell $BASHPID >>> grep SigIgn /proc/$BASHPID/status >> >> After setting all the caught signals back to SIG_DFL, this shell, call it >> pid 811, sets SIGUSR1 to SIG_IGN, since that is the disposition it had when >> its parent was started. This happens before pretty much anything else. >> ... >> Let's say this process has pid 813. In this subshell, there shouldn't be >> any ignored signals after the shell initializes (it's interactive), but it >> does this lazily. >> > > If it should be set to SIG_DFL once anything about signals have to be done, > why it even attempt to reset it to SIG_IGN after the subshell initialize? > And, I cannot say that bringing an ignored signal back alive in the name of > "exit handling" is a "correct behavior"... Posix says two things: that a (...) subshell should start with signal dispositions that are either SIG_DFL or SIG_IGN (if the signal was ignored when the shell creating the subshell was started or when the subshell was created) and that an interactive shell doesn't have to keep signals that were set to SIG_IGN at startup ignored. Interactive shells can do pretty much what they want with signal handlers. >> I get exactly the same results in bash-4.4 running on RHEL7. >> > > I'd like to confirm your results: when I run it once again in my Ubuntu 18 > with bash 4.4 I see the same results. After reading your messages I can do > simpler checks of the behaviour. First, I test 3 different versions of > bash by running: > > - A: Ubuntu 19.04, bash 5.0.3(1)-release > - B: Debian 4.9.189-3, bash 4.4.12(1)-release (Same results on 4.4.20 of > Ubuntu 18.04.3) > - C: CentOS Linux release 7.7.1908, bash 4.2.46(2)-release > > Here are the tests: > > $ trap '' USR1 > $ (trap true EXIT; grep Ign /proc/$BASHPID/status) > > I see: > > A: SigIgn: 0000000000000200 > B: SigIgn: 0000000000000200 > C: SigIgn: 0000000000000200 > > So it is not that within subshells of interactive shells, once you trap > EXIT you get the signal handler reset. In all the above cases it didn't > happen. Yes, you're right. I skewed the results in my example by running `trap' without arguments in the subshell to view the trap dispositions. That was my addition, not in your original script. > > Then I test it by running: > > $ trap '' USR1 > $ (trap true EXIT; (grep Ign /proc/$BASHPID/status) ) > > For this, I get: > > A: SigIgn: 0000000000000200 > B: SigIgn: 0000000000000200 > C: SigIgn: 0000000000000000 > > This is the actual reason why I have my complex test case in the previous > mail: in my deployment there is an error, and I go back to a convenient > machine running like (C) and try to reproduce it. I suddenly end up with > something that causes an error. This appears to have been a bug in bash-4.2, which is many years old. The idea is that the subshell needs to run with USR1 ignored because it is ignored in the parent. So the subshell forks, it inherits the SIG_IGN disposition, and nothing changes the SIGUSR1 disposition after the subshell starts, so it remains ignored. If I can recall correctly, the change came after a long posix group discussion back in 2013 about exactly what the words "at shell startup" and "on entry to the shell" mean. > > Then here is what is inspired by your reply: > > $ trap '' USR1 > $ bash > $ (trap true EXIT; grep Ign /proc/$BASHPID/status) > > For this: > > A: SigIgn: 0000000000000000 > B: SigIgn: 0000000000000000 > C: SigIgn: 0000000000000200 > > This is the behaviour I was reporting. The thing is, the behaviour is > undocumented, and even if you want to document it you don't know how to do > so. Starting the interactive shell permits bash to reset ignored signals to SIG_DFL or catch them. Posix says "An interactive shell may reset or catch signals ignored on entry." and bash does so. This is where the subshell knowing it's part of an interactive shell when it sets the EXIT trap becomes relevant. If you want to look at the code, look at initialize_terminating_signals() and the places in trap.c that call it when setting the EXIT trap. The sequence is as follows: the interactive shell starts, notes that SIGUSR1 was set to SIG_IGN at startup, and catches SIGUSR1. The subshell forks, the SIGUSR1 signal gets set to SIG_IGN (because it was ignored at the interactive shell's startup) and runs trap to set the EXIT trap. The trap command notes that it's running as part of an interactive shell and catches the fatal signals (including SIGUSR1) so it can run the exit trap before the shell exits, as required. This is pretty much what was in my previous message. I don't consider it a bug. -- ``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/
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Signal ignore flags unexpectedly reset after "trap ... EXIT" Chet Ramey <chet.ramey@case.edu> - 2019-10-30 14:50 -0400
csiph-web