🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #228

Re: problem with bash 1.12.1 w/ trap

#228
From: Chet Ramey
Date: Mon, 27 Jul 1992 03:52
40 lines
2062 bytes
> Currently, I cannot get scripts with trap in them to work correctly
> under bash version 1.12.1.

I rewrote the trap and signal handling code for the next version, which
should correct many of the bugs people have found.

>   delay=6
>   trap 'trap 14' 14
>   echo "What is your Quest? \c"
>   (sleep $delay; kill -14 $$ 2>/dev/null)&
>   read YourQuest
>   kill $! 2>/dev/null
>   [ ! -z "$YourQuest" ] && echo "Bah. Humbug. Not interested in $YourQuest" \
>                         || echo "You must be interested in something!"

You're expecting the SIGALRM to interrupt the read, I'm sure.  It doesn't
do so on BSD systems.  On my SunOS 4.1.2 systems, after changing the above
trap command to `trap "echo 14 ; trap 14" 14', I found that out of bash,
ksh-88, /bin/sh, ash, the new BSD sh, and zsh, only bash and zsh even
printed the `14'.  None of those shells let the SIGALRM interrupt the
`read'.

>   PATH=/bin:/usr/bin
>   trap "" 1 2 3 4 5 6 7 8 '9' 10 11 12 13 14 15 16 17 18 \
>                   19 20 21 22 23 24 25 26 27 28 29 30 31
>   set - $(who am i)
>   echo $1

The specific problem with this script is that you've told bash to ignore
SIGCHLD, and version 1.12 does not handle that correctly.  (It sets the
SIGCHLD handler to SIG_IGN in the child shell created to run the command
substitution, and that shell never reaps the `who' and exits.)

Chet

--
``The use of history as therapy means the corruption of history as history.''
	-- Arthur Schlesinger

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu
Technical Details
Message-ID: <9207271152.AA08259.SM@odin.INS.CWRU.Edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!odin.ins.cwru.edu!chet
References: chet@odin.ins.cwru.edu (Chet Ramey)

Show Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!odin.ins.cwru.edu!chet
From: chet@odin.ins.cwru.edu (Chet Ramey)
Subject: Re: problem with bash 1.12.1 w/ trap
Message-ID: <9207271152.AA08259.SM@odin.INS.CWRU.Edu>
Sender: gnulists@ai.mit.edu
Reply-To: chet@po.cwru.edu
Organization: GNUs Not Usenet
References: chet@odin.ins.cwru.edu (Chet Ramey)
Distribution: gnu
Date: Mon, 27 Jul 1992 03:52:17 GMT
Approved: bug-bash@prep.ai.mit.edu
Lines: 41