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


Groups > gnu.bash.bug > #11549

Re: SIGINT handling

From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: SIGINT handling
Date 2015-09-22 19:20 +0100
Message-ID <mailman.1620.1442946025.19560.bug-bash@gnu.org> (permalink)
References (5 earlier) <20150920194542.GB14980@chaz.gmail.com> <560054CE.6000208@case.edu> <20150921210755.GC5598@chaz.gmail.com> <20150922121808.GK25574@eeg.ccf.org> <20150922115842587713157@bob.proulx.com>

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