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


Groups > gnu.bash.bug > #15844

Re: Protect Loop Execution with Traps

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Roger <rogerx.oss@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Protect Loop Execution with Traps
Date Wed, 29 Jan 2020 13:28:40 -0500
Lines 42
Approved bug-bash@gnu.org
Message-ID <mailman.56.1580322529.2384.bug-bash@gnu.org> (permalink)
References <20200128212551.GD12574@localhost4.local> <20200128020322.GA31704@localhost4.local> <20200128134935.GM1350@eeg.ccf.org> <20200128204932.GB12574@localhost4.local> <20200128210721.GU1350@eeg.ccf.org> <59.1580277932@jinx.noi.kre.to> <20200129143352.GY1350@eeg.ccf.org> <20200129182840.GB5533@localhost4.local>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1580322530 18009 209.51.188.17 (29 Jan 2020 18:28:50 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ORA4f5GTXSNbp6kjDcFG/QgBm3vjMjYqjEvS1hG+3W8=; b=ZlXxGD7BVh4aXly1YLUKPoYOctO3SL7t13LvVTADiLVH/YkHa8wwVgMhhGxBMRk5aA OaqgGy89CgsAvMBPgiuJZP722tfC6eht1j1Wdjvxs5YbVWA2zZ1gF0iJbcK3A5aTeVjW ES/kmrUOtBVtS7qQfVaZL3fLIIcBSwjjFEDjllSA29y0ZifJQ4ujpBM1RG/xGf8sK8YB V2Yw2gcV2tdb3hNGF/13w3kbT5hZ4W2tyCzuim0mDnnDnqcD3bFTkJXklMHQFlWkI9yx I18M+QcDNH7ObeGj9s0qwPGoYyzeLLxOfhFWgBmEKyLofxayuhvTL/5VOJq/1ibmJMLV ltYA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ORA4f5GTXSNbp6kjDcFG/QgBm3vjMjYqjEvS1hG+3W8=; b=ffxyDgyxCygD8azDfRxwWO5S0KcYyokC63mcD9Wet6uV4zP5yud8009JqNCjIN3Yt9 dKTnTfyayOLKGxwCU8QOy4WecTymucrwfU9YEXh/PGduY/nd9OaxcbqoxHDnokm+rhz8 9+8NXThnxtYLcHxKGqPMxdjRQu+O7q48Lmq+hyLooofNc2LFheCkmgI4Wv5x2vI4itrm L2pewpJIKYDUddClISZ5fhZ//DrIowVTfcJ1BFXObFVBb1ha32ZYwhV33+xccocdbYmO E4R4lt8/NRZM4HeV8vF1Zk9D8fWYcOwAKi1pKhIVLj0JzqxJBFglf+zn5QyI8/CV7dNH 40Jg==
X-Gm-Message-State APjAAAXvuDyUsDFKdKKIxp9OMGGtGQJAjFUMzOFFg9qGwESGOd4ctoXd a6N/QT7NkkpxPMLTCCeoPepe3/6WMvM=
X-Google-Smtp-Source APXvYqyxg46sQ15+2QHhhOI6GMNjK0381s30+Cgl0yvKm1XoDSaUDePC3IIFJM6ZLTy3kBIpp+UidQ==
X-Received by 2002:a05:620a:2056:: with SMTP id d22mr1157670qka.142.1580322522133; Wed, 29 Jan 2020 10:28:42 -0800 (PST)
Content-Disposition inline
In-Reply-To <20200129143352.GY1350@eeg.ccf.org>
X-PGP-Key http://rogerx.sdf.org/about/armor-F515AC1F231FFC4EF0BCDE7606CEA0ECE2887C75-20170104.asc
User-Agent Mutt/1.10.1 (2018-07-13)
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::730
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 <20200129182840.GB5533@localhost4.local>
X-Mailman-Original-References <20200128212551.GD12574@localhost4.local> <20200128020322.GA31704@localhost4.local> <20200128134935.GM1350@eeg.ccf.org> <20200128204932.GB12574@localhost4.local> <20200128210721.GU1350@eeg.ccf.org> <59.1580277932@jinx.noi.kre.to> <20200129143352.GY1350@eeg.ccf.org>
Xref csiph.com gnu.bash.bug:15844

Show key headers only | View raw


> On Wed, Jan 29, 2020 at 09:33:52AM -0500, Greg Wooledge wrote:
>On Wed, Jan 29, 2020 at 01:05:32PM +0700, Robert Elz wrote:
>> and (with all respect to Gred) please avoid archaic uses, and use the
>> commands as they're currently specified, while "trap - INT" and "trap INT"
>> do the same thing, the former is the standard way, similarly for
>> "kill -INT ..." and "kill -s INT ..." the latter is the modern version.
>
>I had <https://www.cons.org/cracauer/sigint.html> open at the time,
>and got the syntax from there.  He actually uses the numeric signal
>specifiers ("trap 2"), which I replaced with the modern standard naming
>strings; but I didn't replace the legacy single-argument form with
>the "-" form.  Bash, of course, accepts both.

The "Proper handling of SIGINT/SIGQUIT" 
(https://www.cons.org/cracauer/sigint.html) looks to be an excellent 
explanation of the problem described here. (I'll add this to my reading list.)

>You're not going to talk me into using "kill -s" any time soon, though.
>I don't think I've *ever* seen anyone use that.

Ditto.  From my experience, "kill -s" is usually used for init scripts or 
debugging difficult bugs with uniquely connected hardware, etc...

>>   | I'm thinking, put "trap INT; kill -INT $$" inside of it's own function,
>
>Yeah, that's pretty common.
>
>sigint_handler() {
>    trap - INT
>    kill -INT $$
>}
>trap sigint_handler INT
>

Extremely much more readable!  My effort at readability was seemingly five 
steps behind your example here.


-- 
Roger
http://rogerx.sdf.org/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Protect Loop Execution with Traps Roger <rogerx.oss@gmail.com> - 2020-01-29 13:28 -0500

csiph-web