Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16508

Re: approach to async-signal safety in bash

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: approach to async-signal safety in bash
Date Wed, 1 Jul 2020 10:58:02 -0400
Organization ITS, Case Western Reserve University
Lines 48
Approved bug-bash@gnu.org
Message-ID <mailman.764.1593615491.2574.bug-bash@gnu.org> (permalink)
References <pn9hipci.dag@gnui.org> <CAB4+JYLs7vO-9dOb9inSRF0QC7d67U9RJnduk3oWy+MiaFUOug@mail.gmail.com> <4e5be040-0d4c-6ccb-efad-5a33352681d3@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 1593615492 4133 209.51.188.17 (1 Jul 2020 14:58:12 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu
To Godmar Back <godmar@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=1593615487; bh=+BMlPdJwQJG3DIzaDjLKdulQviei+GJSiAQikvqKaTM=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=AioVUNmX7IovsYjai/qyAoo/8xIIoUN7VS7boa9oltGbfdqzxbvyphwa9Twf/Lki1r +whJuJKsB3LtVGiQf972zuqtRSCPDxRNIr1IsQaj7gFQwjsfCStKGW4ciADWbEu6rJU CP6xos/DKKR+tDxvKyXKQSRr5P/S/8iVj5WDE5BwnPUj5rm+Y/Ih2GSCPboYTkyxomH EsN5fzPDiSVU+gGs4wNdgSX39JPcPxgKKuJtovfJ+T2SSw0LtZ46AN4y3UeGAvr9oaB E9BUcrQ7ujuczL8lPu4M7PGBV+ovbYLVRHfaEfBmYZTnS/nmpIg3BEq2AFR0PiYlufJ bw6j0iqw==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1593615485; bh=Jb72X67m0rPbj0IsewQRnU8wEbLUkS0LYWQUdyqQeHM=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=HwpBbgRIcf506GjxXn+rozzz4Pg/rAK0uEtJ2SJqh8sd4g9HE3YA69U2obO8JP2TNu mygXlWmwzh/4SBMSpcIbpJJXZLHaUosn8LJh81O/dDMr9QGoGAAQ4AGnTyo3KY6LLcN CpVRxqfDavS+sZvbxd9vGKfXY1vYNb7fVwQwfZ0MKN133dzfD016MkITM0BlG1Ut6oB a0Ox2/uCe0JVwkvk5cNJ0t5oX2mVk70ZX+Wxb1oa2deiREz3utmbyvbLcXJynlsmHx0 I69HMXFuZp/R0rZmABbu1geMqcCRpQwtBnNbrHGu6+95A5Gbm/CFNNa1VWJYBMwAqrP xAieZm7w==
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=Jb72X67m0rPbj0IsewQRnU8wEbLUkS0LYWQUdyqQeHM=; b=FlatuC5CytAb/kO1/YLdk3LxLpLypIyrFcv03w6yNiEvoiic++nLbhSidT4E6Pjjkk /ZWmZYhyNqfUFSbFI6n1mEXiCnINh7dbz2yZJZD9YyXL4GpG6AryyyxoM/dgI7MjIxbv E0zmmySwlAuKsJ/EPKGRuNqJfUK2YgTcMB6p0647YkMPKGRE546E3yStc0fDMGTqcjdE CZD9JcTc8UslnXcln5o3YNvsHbeR+a9lWqSyrmwAoCY909V9q5tt4WHGScA+E6irEmL/ Yt2TCKNVvJhr78XdmMeOPdNzzp5GTnVySLgH4gjIsIDhr5zQV3s9Jc4gIaRs+ckhnmR1 dK/Q==
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=Jb72X67m0rPbj0IsewQRnU8wEbLUkS0LYWQUdyqQeHM=; b=sF+y9nSYCHTO5Cq9qpdtqVxVJ6OMjMlH8bDAvCcCRwMNuTYv82cG325hwCuxfEhiua p4auniTqJkzMwwh5OOCb4DrREQknqTE4kdQ99GZh+Td6+dV4ozTq/eg3v5nigHQmrkAt 8AnkUTKyuOsbREOiJm5ywGWboIW6qoEC1Z3vZHIHHKsWH39qwqOzPdj4vgV0Jb4KYhUu 6dwQ78hnxza2j9PnwbZfbVoyTryZjgA181feVU/NrL8Le4DGne46Exx22BpDCteCpsrM wfbj2X6K5nLh54rREFppb+VJfkM1A9Gks6JYuIW1MXCp77veKGI1d8jgUl2sVR8rf5u8 QqwA==
X-Gm-Message-State AOAM530Z/do1wjEJhNbKhb4tAmM+3uK4xgICdxeCyxeiO5jk2Y5ZSRME 1gElRhAqBiEx7Dj/TdYg4jr/+NE71zDdGQkxHUtYDez040VRRTl981wnrE96DNEM12UZRXin/8L efmpWpSciLcQ=
X-Received by 2002:aed:35b2:: with SMTP id c47mr26564013qte.324.1593615484739; Wed, 01 Jul 2020 07:58:04 -0700 (PDT)
X-Google-Smtp-Source ABdhPJw1N56VAI6Dvi+EvrR++ya7VbPnTSAJ1QvbZ+YvsCbQmfDml/1IQnYcOOySk3c4yj4eVCkO6w==
X-Received by 2002:aed:35b2:: with SMTP id c47mr26563988qte.324.1593615484445; Wed, 01 Jul 2020 07:58:04 -0700 (PDT)
Autocrypt addr=chet.ramey@case.edu; prefer-encrypt=mutual; keydata= mQGiBEEOsGwRBACFa0A1oa71HSZLWxAx0svXzhOZNQ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0KZiEkEGBECAAkFAkEOsG8CGwwACgkQu1hp 8GTqdKvjcACfZlkVCDwaz/NTO9cy3t69oWpVPNwAnRwe0qk/WL/gfhH346xh5B3HFbFN
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.9.0
In-Reply-To <CAB4+JYLs7vO-9dOb9inSRF0QC7d67U9RJnduk3oWy+MiaFUOug@mail.gmail.com>
Content-Language en-US
X-Mirapoint-IP-Reputation reputation=Good-1, source=Queried, refid=tid=0001.0A020301.5EFC9903.000B, actions=tag
X-Mirapoint-IP-Reputation reputation=good-1, source=Fixed, refid=n/a, actions=tag
X-Junkmail-Status score=7/80, host=mpv1-2015.case.edu
X-Junkmail-PrAS-Raw score=7/80, refid=2.7.2:2020.7.1.143918: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, __SUBJ_ALPHA_END, __TO_MALFORMED_2, __MULTIPLE_RCPTS_TO_X2, __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_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __URI_NO_WWW, __CP_NAME_BODY, __CP_URI_IN_BODY, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138
Received-SPF pass client-ip=129.22.103.226; envelope-from=chet.ramey@case.edu; helo=mpv1-2015.case.edu
X-detected-operating-system by eggs.gnu.org: First seen = 2020/07/01 10:58:05
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 <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 <4e5be040-0d4c-6ccb-efad-5a33352681d3@case.edu>
X-Mailman-Original-References <pn9hipci.dag@gnui.org> <CAB4+JYLs7vO-9dOb9inSRF0QC7d67U9RJnduk3oWy+MiaFUOug@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16508

Show key headers only | View raw


On 6/30/20 4:28 PM, Godmar Back wrote:
> Hi,
> 
> I'm trying to understand what approach bash takes to async-signal safety in
> its design.

I'm always interested in this kind of analysis, since signal handling
conflicts can be a ripe source of deadlocks -- think glibc and its dozens
of internal locks.

> Looking at the bash 5.0 code, I see some comments in the code about
> strategies to protect the jobs array and other data structures from
> arriving SIGCHLD signals, but I have questions about, for instance, these:
> 
> - printable_job_status uses a 'static' variable "temp". However,
> printable_job_status is called during the execution of the builtin command
> "jobs" and here (I believe at least) without blocking or queuing SIGCHLD.

I don't see how. It either calls list_{all,running,stopped}_jobs, which end
up calling map_over_jobs and blocking SIGCHLD there, or jobs_builtin blocks
SIGCHLD itself before calling list_one_job.

> Therefore, if set -b is set, it could be reentered if a child process exits
> at that time. This could clobber 'temp'.
So this and the next one cover set -b, which by design has to notify
asynchronously, out of the signal handler. Maybe it would be better to run
it only if the shell is reading command input at the time the signal
arrives.

> 
> - If set -b is set, calls to notify_job_status from the SIGCHLD handler may
> invoke printf or fprintf(stderr,), which is also called on builtin paths,
> for instance, when executing just "set" and listing all variables/functions.
> 
> - The SIGALRM handler in eval.c calls printf and fflush(stdout), even
> though SIGALRM doesn't appear to be blocked elsewhere where printf() is
> called.

This is another case that I find unlikely to cause problems, since the code
path this call surrounds doesn't include other calls to printf. The signal
handler is only installed while the shell is reading a command.


-- 
``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


Thread

Re: approach to async-signal safety in bash Chet Ramey <chet.ramey@case.edu> - 2020-07-01 10:58 -0400

csiph-web