Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15514
| 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, 16 Oct 2019 09:36:35 -0400 |
| Organization | ITS, Case Western Reserve University |
| Lines | 100 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.862.1571233005.9715.bug-bash@gnu.org> (permalink) |
| References | <CAOArY3X4VXAkmoCh0vsRZuHsJpw=jOF4_uLocsap1bG+QpK1iQ@mail.gmail.com> <970b8a07-0f94-6d3d-c2f5-cf9a1eba4390@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 1571233006 23372 209.51.188.17 (16 Oct 2019 13:36:46 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=1571233000; bh=Egb/zAyxUmnYvZMe2qKn/he3mWnPqToTlTuwunpkIk4=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=ezsPsT/kWvQ8ZoMISvdHTUkv6bDS1P2Az50bk5h4EBDUzPIKlzLvaKTbqnH6ng/AQj 7oYfK4QreoMN25zZAoYq91vQqnaMuaw8mET7LOjQkcunlHSwlDBOMA4vYhHiO4dBNi/ O/CdB+B3o8PftbP0SNUaPfQ/lNBJKUB8C7d/M1dAunw0qyGN40jwV/N3a7NDmJL3Wu4 srcupGamOBOGWRtRTFOQC4RHJyvlnZ5Qu3xA3UFKXjuuKbeHdx3sugqeJ+cds+MaBeQ JWcTSGIJSykwvwdGpgmYf7aniGMW+9/gWMP/Zs5lT0IecKIse3PBSi51xOt1bKPR3FI ScGG9vZQ== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1571232999; bh=VT+0NGvu56ND2p3O040I6dxpSWxS05o/3Vy4IaYmNUs=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=TdVnr1ugBTecPJw7vxlCmfCvAPBYiuI3cOVo/G2xjpi6VCz4MkacfMxtTth4jbr4na KinUCXfMnLItA3nuqTMap2RwlxIJOs5HTlm85gYvGBlbWDXEjcZZYGQ3Us4PrV+1QaO Zu+1FKaW2ULiWvgVQ8Leml6bgwSRdhP+NJKqoPBvkhZnO5cViiVNLt7p+bvVIoWu91D 6CCdTjbKwsKXI2gwW9qMQOee4lhtduylg5z/LeZJUVH5q4lc27L9hfXuIz8jHjaFqtf oGdCC4xmMNWi6nDjdtz4WVDKGX+ZVUBfHsGzawiv/75yKczacWIPCC7gFIbH5DKi0Bv hz2yKM+g== |
| 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=VT+0NGvu56ND2p3O040I6dxpSWxS05o/3Vy4IaYmNUs=; b=OGbLLfgMCDPIj21ln18nwbsGvBC9AU4JUL1jP5CFnptc0wZOS4ZoDjEQrtmqfTX/kR NWkf3BiO/lIkAUfJT6muN3HEQT4Sm8VPlZCmGGbEEHB6H6L64wLB8CU7zxFQv1Dffj8T 1VUln6zthLyeTjEvp2qx9MTOSFjkasINg+Io/Mo7YUSw7YQQuRGJSF5qPT3/lpVbCTYo oVJ6E0RuDXpX2ToOCYnFm8I3u3xRu6OPhhsISrq1eItxnLmMV/bO+JLrbsSuWOoywsri j3PUbJm97Eh1SsmgkXe5DdEMq71SkUm2tzBCV7RQ23D1l/4HuUSlD/wh25vtDjgkNglO TrJw== |
| 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=VT+0NGvu56ND2p3O040I6dxpSWxS05o/3Vy4IaYmNUs=; b=rMvf4Y1V7FVyuB3drtGDvhYZ88KWFFgen3l9qWkLBX5kGZibZ3gr5u0MC5PXaFx1WH oMalrOdPUo8+mY0jNlYAF5SJJR6ptNv/WcPkcVMtNZ4qJaKyp4EbD3nyIqEjcS8pzJ3x PGc9Dw2YX7QqYdeK5ql3m/PCh4V+XgpYMxL/hxYEmNVThaApBO/Zz/HIQFiLiL5D2d5f c5sg5B4H3qI719BbRLTgKDh8VDoIyUgjKunM0l9Q/OnflzmDrv4O17PZsLDoPtIZAMrC TdnRg+B+TtK7ujWXWUk6RCJVIxew0DJbkZeuDBeSQNXhV/2zugSeIXFban2xOfEkWo1K D0qA== |
| X-Gm-Message-State | APjAAAW9VL5ErQTLGKpQtmpCVnyJenYPAsDBkyFRfTnp8sJV3/8u2ENt V3Bx0UoEieA7zI8DHFWB3jTGUjAhOB+Cy3L5VwhzHjo2E8zV+SKODNUPDdtNy2AdGK4/TdEWhDf AyIvrYMPiVX4= |
| X-Received | by 2002:a92:de02:: with SMTP id x2mr12060344ilm.3.1571232998373; Wed, 16 Oct 2019 06:36:38 -0700 (PDT) |
| X-Google-Smtp-Source | APXvYqzK2TNtyIO4wkQfLv+0qZjOlWtKcUsi/7guC8HsTrzVYNzNoaRV5wYOGzFnl4XrJYFn8LrQ+A== |
| X-Received | by 2002:a92:de02:: with SMTP id x2mr12060311ilm.3.1571232997936; Wed, 16 Oct 2019 06:36:37 -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 | <CAOArY3X4VXAkmoCh0vsRZuHsJpw=jOF4_uLocsap1bG+QpK1iQ@mail.gmail.com> |
| Content-Language | en-US |
| X-Junkmail-Status | score=7/90, host=mpv2-2015.case.edu |
| X-Junkmail-PrAS-Raw | score=7/90, refid=2.7.2:2019.10.16.125716: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_NAME_BODY, __CP_URI_IN_BODY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODY_SIZE_3000_3999, __MIME_TEXT_P1, __MIME_TEXT_ONLY, __URI_NS, HTML_00_01, [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.227 |
| 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 | <970b8a07-0f94-6d3d-c2f5-cf9a1eba4390@case.edu> |
| X-Mailman-Original-References | <CAOArY3X4VXAkmoCh0vsRZuHsJpw=jOF4_uLocsap1bG+QpK1iQ@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15514 |
Show key headers only | View raw
On 10/15/19 5:22 AM, Isaac To wrote: > Bash Version: 5.0 > Patch Level: 3 > Release Status: release > > Description: > > When trying to write a program and start it in an initrc script, I observed > a strange behavior: if a subshell is started by a subshell of that script, > and the inner subshell runs "trap ... EXIT", it unsets the signal ignore > flag of other signals. I'm not sure whether this should be called a bug, > or whether it is a problem caused by my own configuration. Anyway here is > how I reproduce my problem. OK, let's go through what happens to signals when you run this. > $ cat t.sh > echo t $BASHPID > trap '' USR1 This bash process, lets say pid 806, sets the disposition of SIGUSR1 to SIG_IGN. > grep SigIgn /proc/$BASHPID/status Presumably this reflects it; I don't know how to interpret the output. > bash --rcfile t2.sh You start an interactive shell, say pid 809. This means that the shell remembers that SIGUSR1 was ignored when it started but sets the handler to a fatal signal catcher function. It will set the disposition to SIG_IGN in a child proess immediately after it forks. This means, for instance, that the greps run with SIGUSR1 set to SIG_IGN. The other thing an interactive shell does is catch all fatal signals so it can clean up. This means that a subshell has to undo this by setting all these signals to SIG_DFL when it starts. Since this shell is interactive, all subshells it runs know they are children of an interactive shell. > $ cat t2.sh > echo t2 $BASHPID > grep SigIgn /proc/$BASHPID/status This gives you the normal set of ignored signals for an interactive shell: SIGQUIT/SIGTSTP/SIGTTOU/SIGTTIN. SIGUSR1, a fatal signal, is caught. > ( > 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. Bash will install signal handlers for everything it needs to catch, and, since this is still an interactive shell, it will catch signals that are ignored when it starts. It does this lazily -- when it needs to do something with signal handlers. This turns out to matter; see below. > ( > echo subsubshell $BASHPID 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. This is probably where the confusion arises. It's arguably a bug that bash doesn't change the signals to caught right away. > grep SigIgn /proc/$BASHPID/status > echo trap $BASHPID > trap 'echo hello' EXIT When the exit trap is installed, bash needs to install handlers for all the fatal signals, so it can run the exit trap (if possible) if it receives one. Since it's an interactive shell, it installs handlers for everything, even signals, like SIGUSR1, that were ignored when the shell started. Once it's done that, there are no longer any ignored signals. > Note that the final SigIgn flag is completely reset, which is what I won't > expect. The same problem won't occur if --rcfile is not used in t.sh. And > the problem also didn't show up in bash 4.4. I get exactly the same results in bash-4.4 running on RHEL7. -- ``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-16 09:36 -0400
csiph-web