ash-20010805-1 calling trap incorrectly.

Moreland, Kenneth kmorel@sandia.gov
Thu Aug 23 10:41:00 GMT 2001


I've recently installed cygwin on Windows 2000 and noticed a problem with
sh, specifically the sh included in ash-20010805-1.tar.bz2.  When using the
<< form of redirection AND using a `command || command` command substitution
within the text of the redirection where the first command is not a shell
built in, the trap for signal 0 is called.  The trap appears to be called in
a subshell of some sort because it cannot affect the standard output or
error streams nor can it change any shell variables.  However, its effects
can be seen indirectly through the manipulation of files.  As an example,
consider the following shell script:


#! /bin/sh

rm -f out

trap "echo Caught trap! >> out" 0

echo "Before cat." > out

cat <<EOF
`/bin/echo hello || /bin/echo world`
EOF

echo "After cat." >> out

trap 0

echo "Trap cleared." >> out

cat out


When run with the latest version of the shell script, the output is:

hello
Before cat.
Caught trap!
After cat.
Trap cleared.

As you can see, the signal 0 is somehow raised in the cat command and
"Caught trap!" is inserted into the file out.  When I back out of the latest
version of ash to ash-20010425.tar.gz, I get the correct output:

hello
Before cat.
After cat.
Trap cleared.

I first noticed this bug while using autoconf and libtool.  The
AC_PROG_LIBTOOL macro generated script code with the described conditions,
which caused a trap command to be called that deleted a header file which
subsequent compiler tests depended on.

-Ken

   ****      Kenneth Moreland
    ***      Sandia National Laboratories
***********  
*** *** ***  email: kmorel@sandia.gov
**  ***  **  phone: (505) 844-8919
    ***      fax:   (505) 844-9297


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list