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


Groups > gnu.bash.bug > #15844

Re: Protect Loop Execution with Traps

From Roger <rogerx.oss@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Protect Loop Execution with Traps
Date 2020-01-29 13:28 -0500
Message-ID <mailman.56.1580322529.2384.bug-bash@gnu.org> (permalink)
References (3 earlier) <20200128204932.GB12574@localhost4.local> <20200128210721.GU1350@eeg.ccf.org> <59.1580277932@jinx.noi.kre.to> <20200129143352.GY1350@eeg.ccf.org> <20200129182840.GB5533@localhost4.local>

Show all headers | 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