[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Portability problems in autoconf manual
From: |
Eric Blake |
Subject: |
Re: Portability problems in autoconf manual |
Date: |
Wed, 10 Jun 2009 06:41:21 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Ralf Wildenhues on 6/8/2009 2:59 PM:
>
> If I understand this correctly, then there are one, or even two ways to
> portably reset traps to their default value: either use reset only one
> signal at a time:
>
> trap 1; trap 2; trap 13; trap 15
Remember, POSIX 2001 specified that you use either 0 arguments or 2 or
more, but left the use of exactly one argument undefined. Only POSIX 2008
introduced the possibility of a syntactically valid use of exactly 1
argument. But you are certainly on to something; it looks like dash does
indeed recognize a 1-argument trap call as a reset:
$ dash -c 'trap echo 0; trap; trap 0; trap; echo done'
trap -- 'echo' EXIT
done
$
As do most other shells that I tested: Solaris /bin/sh, bash, zsh, pdksh,
ash. However, I did find an exception:
$ posh -c 'trap : 0; trap; trap 0; trap; echo done'
trap -- : EXIT
posh: trap: no signals specified
$ echo $?
1
But posh is already the oddball, as (depending on the version) it requires
names instead of numbers (although I know that has already been brought up
with the debian folks).
> or factor the code based on whether the shell groks resetting of traps
> with a numeric first argument (and assuming it will accept '-'
> otherwise):
You are on to something here. Notice that we don't even have to worry
about whether 0 is a command or alias, if we insist on doing things one
trap at a time and rely on the syntax error of posh as the determining
factor instead:
if (trap 0) 2>/dev/null ; then
trap 0; trap 1; trap 2
else
trap - 0 1 2
fi
In my testing, this worked for Solaris /bin/sh, dash, bash, zsh, pdksh,
and posh, modulo posh's need for signal names. Anyone have a
counterexample, before I publish this as a portable way to reset traps?
Unfortunately, we cannot wrap this logic in an ease-of-use function:
# trap_default TRAP[...]
# ----------------------
# For each TRAP number, reset the trap to its default state.
if (trap 0) 2>/dev/null ; then
trap_default()
{
for num
do
trap $num
done
}
else
trap_default()
{
trap - $*
}
fi
since using trap inside a function does not properly affect the outer
environment, on at least zsh (even with emulate sh).
But we COULD make an AS_TRAP_DEFAULT macro that uses m4 expansion time to
break a list into multiple calls as needed.
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkovqfEACgkQ84KuGfSFAYDxQACaA4O1DxGKKUMYcoQeUvhuG1Ov
Oq0AoMS5+smpn0T/9NAF4g+wrznWw57N
=8Iz9
-----END PGP SIGNATURE-----