Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Jim Meyering
Dmitry V. Levin wrote: > On Sun, Jan 31, 2010 at 01:04:09AM +0100, Bruno Haible wrote: ... >> For the tests, I am inclined to provide the exit >> code '77' (= SKIP), rather than '1' (= FAIL): If a test is terminated >> by Ctrl-C, it has neither passed nor failed. > > Yes, it makes sense. Actually,

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Ralf Wildenhues
Hello Dmitry, * Dmitry V. Levin wrote on Sat, Jan 30, 2010 at 08:12:01PM CET: > There is a comment about shell signal handlers in gnulib-tool saying that > "The value of $? is 128 + signal number and is set before the > trap-registered command is run". Unfortunately, this comment is wrong, > and

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Dmitry V. Levin wrote: > This would break the "If removal fails" statement. > Let's pass exit code to this function as an argument: > > remove_tmp_() > { > __st=$1 > [...] > trap 'remove_tmp_ $?' 0 Yes, you're right. Here's an updated proposed patch: 2010-01-30 Bruno Haible

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Dmitry V. Levin
On Sun, Jan 31, 2010 at 01:51:59AM +0100, Bruno Haible wrote: > Additionally, another proposed change prompted by Dmitry's patch. > > The Autoconf manual > > says: > "the state of ‘$?’ is not reliable when entering a sh

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Dmitry V. Levin wrote: > > -trap 'rm -fr $tmpfiles' 1 2 3 15 > > +trap 'rm -fr $tmpfiles; exit 77' 1 2 3 15 > > According to "Limitations of Builtins" chapter in the autoconf > manual, plain "exit 77" is not portable; it has to be written > as "(exit 77); exit 77". Plain "exit 77" is not portable

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Dmitry V. Levin
On Sun, Jan 31, 2010 at 01:41:33AM +0100, Bruno Haible wrote: [...] > TMP_BASE=update-copyright.test > -trap 'rm -f $TMP_BASE*' 0 1 2 3 15 > +trap 'status=$?; rm -f $TMP_BASE*; exit $status' 0 > +trap 'rm -f $TMP_BASE*; (exit 77); exit 77' 1 2 3 15 The signal trap is a bit redundant, it could be

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Additionally, another proposed change prompted by Dmitry's patch. The Autoconf manual says: "the state of ‘$?’ is not reliable when entering a shell function. This has the effect that using a function as the first co

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Hi Jim, > I'll propose patches for gnulib-tool and most of the tests, and leave > bootstrap, tests/test-vc-list-files*.sh, tests/test-update-copyright.sh > to Jim. Here's a proposed patch for some of these: 2010-01-30 Bruno Haible Don't use $? in a trap handler for a signal.

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Dmitry V. Levin
On Sun, Jan 31, 2010 at 01:22:34AM +0100, Bruno Haible wrote: > Here is part 2 of the proposed fixes. [...] > -trap 'rm -fr $tmpfiles' 1 2 3 15 > +trap 'rm -fr $tmpfiles; exit 77' 1 2 3 15 According to "Limitations of Builtins" chapter in the autoconf manual, plain "exit 77" is not portable; it ha

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Dmitry V. Levin
On Sun, Jan 31, 2010 at 01:04:09AM +0100, Bruno Haible wrote: [...] > > Proposed patch is attached. > > Sorry, but I don't understand why you chose 143 as exit code, making it look > like the process died from SIGTERM when in fact in may have been SIGINT. > There seem to be two conventions for the

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Here is part 2 of the proposed fixes. 2010-01-30 Bruno Haible Don't continue executing a test after catching a fatal signal. * tests/test-atexit.sh (trap 1-15): After removing the temporary files, exit with code 77. * tests/test-binary-io.sh (trap 1-15): Likewi

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Here's part 1 of the fixes, as I would like to see it. Opinions? 2010-01-30 Bruno Haible Don't use $? in a trap handler for a signal. * gnulib-tool (trap 1-15): Exit with exit status 1. * MODULES.html.sh (trap 1-15): Likewise. Reported by Dmitry V. Levin . ---

Re: [PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Bruno Haible
Hi Dmitry, The 'trap' issue is complicated enough that, before answering your mail, I'd like to point out my understanding of the issue. Sources: - POSIX - Autoconf manual

[PATCH] Fix exit status of signal handlers in shell scripts

2010-01-30 Thread Dmitry V. Levin
Hi, There is a comment about shell signal handlers in gnulib-tool saying that "The value of $? is 128 + signal number and is set before the trap-registered command is run". Unfortunately, this comment is wrong, and it seems to be a widespread misunderstanding. The GNU Autoconf manual says that "