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


Groups > gnu.bash.bug > #11549

Re: SIGINT handling

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail
From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: SIGINT handling
Date Tue, 22 Sep 2015 19:20:15 +0100
Lines 51
Approved bug-bash@gnu.org
Message-ID <mailman.1620.1442946025.19560.bug-bash@gnu.org> (permalink)
References <55FDC8B4.4000505@case.edu> <20150919213101.GA4393@chaz.gmail.com> <55FE0BB8.8040500@case.edu> <20150920155219.GA8614@chaz.gmail.com> <20150920161245.GA14980@chaz.gmail.com> <20150920194542.GB14980@chaz.gmail.com> <560054CE.6000208@case.edu> <20150921210755.GC5598@chaz.gmail.com> <20150922121808.GK25574@eeg.ccf.org> <20150922115842587713157@bob.proulx.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1442946026 12746 208.118.235.17 (22 Sep 2015 18:20:26 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=20120113; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=K/4qRJim9hIIRd4/vRRtT6wk57dP6qu2YUVxT9iQjDs=; b=ExXuRW7Z47iSVxNz21nqrGf2S/pM6GxPETJXR7Yv+KBhFVZDdEqspOPbukthaaDFZx 6T79IwkVyHiqKkGdMLN3BLvlZt+w1z62xUkVpf6oZ1QzyA6UhxHtOJBD+9GqEwFxJLx5 91ebaUMcMnZ7D2i+LiHpJg+iHr229sCNVTQNEyASpu538KgDtegwg8D8GI0Wr3RN1MUz f8TSfHnd/TMv4u3X4RvUf3xf/J+5k4kFsdeqdqXZ7yyxbpB3o3ldkSAO9gB8ljtlSF5E UZkvlh04C6iFK57cGgWA8tOuswF/DCn9foPeilm+21aMJOpk13frzY8IIssbi4uOql/a V4vA==
X-Received by 10.180.109.135 with SMTP id hs7mr22431418wib.12.1442946018518; Tue, 22 Sep 2015 11:20:18 -0700 (PDT)
Content-Disposition inline
In-Reply-To <20150922115842587713157@bob.proulx.com>
User-Agent Mutt/1.5.21 (2010-09-15)
X-detected-operating-system by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value).
X-Received-From 2a00:1450:400c:c05::22d
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.14
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 <http://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>
Xref csiph.com gnu.bash.bug:11549

Show key headers only | View raw


2015-09-22 12:04:45 -0600, Bob Proulx:
> Greg Wooledge wrote:
> > Just for the record, ping is the *classic* example of an incorrectly
> > written application that traps SIGINT but doesn't kill itself with
> > SIGINT afterward.  (This seems to be true on multiple systems -- at
> > the very least, HP-UX and Linux pings both suffer from it.)
> 
> The command I run into the problem most with is 'rsync' in a loop.
> 
>   EXIT VALUES
>        0      Success
>   ...
>        20     Received SIGUSR1 or SIGINT
> 
> Which forces me to write such things this way.
> 
>   rsync ...
>   rc=$?
>   if [ $rc -eq 20 ]; then
>     kill -INT $$
>   fi
>   if [ $rc -ne 0 ]; then
>     echo "Error: failed: ..." 1>&2
>     exit 1
>   fi
[...]

Another (generic) work-around as mentioned at
http://unix.stackexchange.com/a/230568
and here is to add:

trap '
  trap - INT
  kill -s INT "$$"
' INT

That doesn't work properly if there are subshells though.

That basically turns a WCE shell to WUE (for very simple scripts).

For SIGQUIT, you'd probably want to disable core dumps as well:
  
trap '
  trap - QUIT
  ulimit -c 0
  kill -s QUIT "$$"
' QUIT

-- 
Stephane

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


Thread

Re: SIGINT handling Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-09-22 19:20 +0100

csiph-web