X-Spam-Check-By: sourceware.org Message-ID: <4681DFBD.7040906@byu.net> Date: Tue, 26 Jun 2007 21:55:41 -0600 From: Eric Blake User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070509 Thunderbird/1.5.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: cygwin AT cygwin DOT com, cowboy AT linux DOT vnet DOT ibm DOT com Subject: Re: Bash is broken wrt trap :( References: <4681CDCD DOT 7030709 AT linux DOT vnet DOT ibm DOT com> In-Reply-To: <4681CDCD.7030709@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Richard A Nelson on 6/26/2007 8:39 PM: > Cygwin bash is actually a newer version than Debian/RH ships - but has > one flaw not shared by the other distributions. You left out one important fact - exactly which version of bash are you running on the three machines you tested? > ERROR="*** ERROR *** ERROR *** ERROR ***"; > trap "echo \"$0:$ERROR\";" ERR; > if [ -n "$BASH" -a "${OS:0:6}" != 'CYGWIN' ]; then > UNWIND="trap 'false' RETURN;return 1"; Traps on ERR and RETURN are not specified by POSIX, so you are already using non-portable behavior, and are only guaranteed what is documented in the bash man page. And you do realize that the release notes for bash 3.2 included this note, in CHANGES: z. The inheritence of the DEBUG, RETURN, and ERR traps is now dependent only on the settings of the `functrace' and `errtrace' shell options, rather than whether or not the shell is in debugging mode. So maybe you should investigate all your shell settings, and see what they are set to in the different environments. And it very well could be that upstream changed intentionally between the versions of bash you are running on the different machines, although the effect you are seeing may be an unintentional side effect of some other change that was thought to be harmless. And maybe the problem isn't in bash, but in your set of default shell option settings. At any rate, to my quick glance, f(){ trap "trap 'false' RETURN; return 1" RETURN } seems reasonable enough. You are telling the function that on the first return, it should install a different trap handler on the return, then return, which triggers the new RETURN trap, which in turn executes false. On the other hand, f(){ trap "trap 'false' RETURN; return 1" RETURN trap "trap 'false' RETURN; return 1" ERR } seems fishy. On error, the ERR trap should install a trap handler on return, then return with a non-zero value - does that count as an error? And even if the return isn't an error, it then invokes the second RETURN trap function of false, which IS an error. So either way, control should once again invoke the ERR trap, which installs a trap handler on return, ... Maybe you should also have something in your ERR trap that resets the ERR trap back to normal, and see if that makes a difference so that the RETURN trap is not considered as triggering the ERR trap. You may also want to raise this issue on the bash mailing list, and see if the upstream maintainer, Chet, has any insight into how he intended for returns inside of traps to behave. I'm not quite sure I see any way that a cygwin-specific patch could be causing this behavior. But I'll still try to trace it further, and actually step through bash in a debugger, if I can find the time. > > ksh93 will propagate the error upwards via the 'return 1' clause. So it sounds like ksh's interpretation was that return invoked from inside a trap cannot trigger further traps. Maybe Chet needs to adopt that rule, too? - -- Don't work too hard, make some time for fun as well! Eric Blake ebb9 AT byu DOT net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGgd+884KuGfSFAYARAl52AJ990Rmga4Z32gLIMba8y4ApqFhAQACfQEt7 RfJz9eR9dUpBrRlH7FvVKoM= =zC+8 -----END PGP SIGNATURE----- -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/