autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] docs: signal-related bugs and incompatibilities for the shel


From: Stefano Lattarini
Subject: Re: [PATCH] docs: signal-related bugs and incompatibilities for the shells
Date: Tue, 13 Sep 2011 19:50:51 +0200
User-agent: KMail/1.13.7 (Linux/2.6.30-2-686; KDE/4.6.5; i686; ; )

On Tuesday 13 September 2011, Stefano Lattarini wrote:

> * doc/autoconf.texi (Signal handling): New paragraph.

> (@menu at "Portable Shell", @detailmenu): Update.

>

> Motivated by recent discussion on the bug-autoconf list, as well

> as work in the automake testsuite:

> <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00003.html>

> <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>

> <http://lists.gnu.org/archive/html/automake-patches/2011-09/msg00066.html>

> ---

> ChangeLog | 7 ++++

> doc/autoconf.texi | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++

> 2 files changed, 101 insertions(+), 0 deletions(-)

>

> diff --git a/ChangeLog b/ChangeLog

> index ab74303..e122686 100644

> --- a/ChangeLog

> +++ b/ChangeLog

> @@ -1,6 +1,13 @@

> 2011-09-13 Stefano Lattarini <address@hidden>

>

> docs: signal-related bugs and incompatibilities for the shells

> + Motivated by recent discussion on the bug-autoconf list, as well

> + as work in the automake testsuite:

> + <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00003.html>

> + <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>

> + <http://lists.gnu.org/archive/html/automake-patches/2011-09/msg00066.html>

> + * doc/autoconf.texi (Signal handling): New paragraph.

> + (@menu at "Portable Shell", @detailmenu): Update.

>

> 2011-08-16 Stefano Lattarini <address@hidden>

>

> diff --git a/doc/autoconf.texi b/doc/autoconf.texi

> index 3377afe..b71eb6d 100644

> --- a/doc/autoconf.texi

> +++ b/doc/autoconf.texi

> @@ -509,6 +509,7 @@ Portable Shell Programming

> * Shellology:: A zoology of shells

> * Here-Documents:: Quirks and tricks

> * File Descriptors:: FDs and redirections

> +* Signal handling:: Shells, signals, and headaches

> * File System Conventions:: File names

> * Shell Pattern Matching:: Pattern matching

> * Shell Substitutions:: Variable and command expansions

> @@ -15070,6 +15071,7 @@ subset described above, is fairly portable nowadays. Also please see

> * Shellology:: A zoology of shells

> * Here-Documents:: Quirks and tricks

> * File Descriptors:: FDs and redirections

> +* Signal handling:: Shells, signals, and headaches

> * File System Conventions:: File names

> * Shell Pattern Matching:: Pattern matching

> * Shell Substitutions:: Variable and command expansions

> @@ -15521,6 +15523,98 @@ ksh[1]: exec: 10: not found

> 127

> @end example

>

> address@hidden <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>

> address@hidden Signal handling

> address@hidden Signal handling

> address@hidden Signal handling in the shell

> address@hidden Signals, shells and

> +

> +Portable handling of signals within the shell is another major source of

> +headaches. This is worsened by the fact that various different, mutually

> +incompatible approaches are possible in this area, each with its

> +distinctive merits and demerits. A detailed description of these possible

> +approaches, as well as of their the pros and cons, can be found in

> address@hidden://www.cons.org/cracauer/sigint.html, this article}.

> +

> +Solaris 10 @command{/bin/sh} automatically trap most signals by default;

> address@hidden See: <http://dbaspot.com/shell/396118-bourne-shell-exit-code-term.html>

> +the shell still exits with error upon termination by one of those signals,

> +but in such a case the exit status might be somewhat unexpected (even if

> +allowed by POSIX, strictly speaking):

> +

> address@hidden

> +$ @kbd{bash -c 'kill -1 $$'; echo $?} # Will exit 128 + (signal number).

> +Hangup

> +129

> +$ @kbd{/bin/ksh -c 'kill -15 $$'; echo $?} # Likewise.

> +Terminated

> +143

> +$ @kbd{for sig in 1 2 3 15; do}

> +> @kbd{ echo $sig:}

> +> @kbd{ /bin/sh -c "kill -$s \$\$"; echo $?}

> +> @kbd{done}

> +signal 1:

> +Hangup

> +129

> +signal 2:

> +208

> +signal 3:

> +208

> +signal 15:

> +208

> address@hidden example

> +

> +This gets even worse if one is using the POSIX `wait' interface to get

> +details about the shell process terminations: it will result that the

> +shell exited normally, not upon receiving a signal.

> +

> address@hidden

> +$ @kbd{cat > foo.c <<'END'}

> +#include <stdio.h>

> +#include <stdlib.h>

> +#include <sys/wait.h>

> +int main(void)

> address@hidden

> + int status = system("kill -15 $$");

> + printf ("Terminated by signal: %s\n",

> + WIFSIGNALED (status) ? "yes" : "no");

> + printf ("Exited normally: %s\n",

> + WIFEXITED (status) ? "yes" : "no");

> + return 0;

> address@hidden

> +END

> address@hidden $$ font-lock

> +$ @kbd{cc -o foo foo.c}

> +$ @kbd{./a.out} # On GNU/Linux

> +Terminated by signal: no

> +Exited normally: yes

> +$ @kbd{./a.out} # On Solaris 10

> +Terminated by signal: yes

> +Exited normally: no

> address@hidden example

> +

> +Some shells seem to handle @code{SIGQUIT} specially: they ignore it even

> +if it is not blocked, and even if the shell is not running interactively

> +(in fact, even if the shell has no attached tty); among these shells

> +are at least Bash (from version 2 onwards), Zsh 4.3.12, Solaris 10

> address@hidden/bin/ksh} and @code{/usr/xpg4/bin/sh}, and AT&T @code{ksh93} (2011).

> +Still, @code{SIGQUIT} seems to be trappable quite portably within all

> +these shells. OTOH, some other shells doesn't special-case the handling

> +of @code{SIGQUIT}; among these shells are at least @code{pdksh} 5.2.14,

> +Solaris 10 and NetBSD 5.1 @code{/bin/sh}, and the Almquist Shell 0.5.5.1.

> +

> +Some shells (especially Korn shells and derivatives) might try to

> +propagate to themselves a signal that has killed a child process; this is

> +not a bug, but a conscious design choice (although its overall value might

> +be debatable). The exact details of how this is attained vary from shell

> +to shell. For example, upon running @code{perl -e 'kill 2, $$'}, after

> +the perl process has been interrupted AT&T @code{ksh93} (2011) will

> +proceed to send itself a @code{SIGINT}, while Solaris 10 @code{/bin/ksh}

> +and @code{/usr/xpg4/bin/sh} will proceed to exit with status 130 (i.e.,

> +128 + 2). In any case, if there is an active trap associated with

> address@hidden, those shells will correctly execute it.

> +

> address@hidden Shell file descriptors

> @node File System Conventions

> @section File System Conventions

> @cindex File system conventions

>

And consider this squashed in:


diff --git a/doc/autoconf.texi b/doc/autoconf.texi

index b71eb6d..dcdbe98 100644

--- a/doc/autoconf.texi

+++ b/doc/autoconf.texi

@@ -15570,12 +15570,12 @@ shell exited normally, not upon receiving a signal.

@example

$ @kbd{cat > foo.c <<'END'}

-#include <stdio.h>

-#include <stdlib.h>

-#include <sys/wait.h>

+#include <stdio.h> /* for printf */

+#include <stdlib.h> /* for system */

+#include <sys/wait.h> /* for WIF* macros */

int main(void)

@{

- int status = system("kill -15 $$");

+ int status = system ("kill -15 $$");

printf ("Terminated by signal: %s\n",

WIFSIGNALED (status) ? "yes" : "no");

printf ("Exited normally: %s\n",


Sorry for the noise,

Stefano


reply via email to

[Prev in Thread] Current Thread [Next in Thread]