Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Robert Elz Newsgroups: gnu.bash.bug Subject: Re: Protect Loop Execution with Traps Date: Wed, 29 Jan 2020 13:05:32 +0700 Lines: 40 Approved: bug-bash@gnu.org Message-ID: 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> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1580278051 27610 209.51.188.17 (29 Jan 2020 06:07:31 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Greg Wooledge , bug-bash@gnu.org To: Roger Envelope-to: bug-bash@gnu.org In-Reply-To: <20200128212551.GD12574@localhost4.local> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 2001:3c8:9009:181::2 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <59.1580277932@jinx.noi.kre.to> 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> Xref: csiph.com gnu.bash.bug:15833 Date: Tue, 28 Jan 2020 16:25:51 -0500 From: Roger Message-ID: <20200128212551.GD12574@localhost4.local> | Wow, " trap 'trap INT; kill -INT $$' INT " not easily readable for me. You can often help with things like that by reformatting trap ' trap - INT kill -s INT $$ ' INT 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. | A trap calling kill inside of a trap. Quite common. Try to avoid recursive traps however, those will blow your stack and result in a core dump from bash if you're not careful. | I'm thinking, put "trap INT; kill -INT $$" inside of it's own function, That's acceptable, sometimes perferable, sometimes just more complexity for no real benefit (makes code harder to understand). | This trap stuff has me pulling out my hair, traps can do that. In general, any programming dealing with async events is much trickier to get right than simple synchronous programming. At least traps are only ever executed between commands, which avoids lots of otherwise potentially impossible to deal with situations (the signal that invokes the trap might have occurred anywhere). kre