Imported from ../bash-4.0-rc1.tar.gz.
[platform/upstream/bash.git] / builtins / trap.def
index 1ecbfbd..a8da71d 100644 (file)
@@ -1,43 +1,55 @@
 This file is trap.def, from which is created trap.c.
 It implements the builtin "trap" in Bash.
 
 This file is trap.def, from which is created trap.c.
 It implements the builtin "trap" in Bash.
 
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES trap.c
 
 $BUILTIN trap
 $FUNCTION trap_builtin
 
 $PRODUCES trap.c
 
 $BUILTIN trap
 $FUNCTION trap_builtin
-$SHORT_DOC trap [-lp] [arg signal_spec ...]
-The command ARG is to be read and executed when the shell receives
+$SHORT_DOC trap [-lp] [[arg] signal_spec ...]
+Trap signals and other events.
+
+Defines and activates handlers to be run when the shell receives signals
+or other conditions.
+
+ARG is a command to be read and executed when the shell receives the
 signal(s) SIGNAL_SPEC.  If ARG is absent (and a single SIGNAL_SPEC
 is supplied) or `-', each specified signal is reset to its original
 value.  If ARG is the null string each SIGNAL_SPEC is ignored by the
 signal(s) SIGNAL_SPEC.  If ARG is absent (and a single SIGNAL_SPEC
 is supplied) or `-', each specified signal is reset to its original
 value.  If ARG is the null string each SIGNAL_SPEC is ignored by the
-shell and by the commands it invokes.  If a SIGNAL_SPEC is EXIT (0)
-the command ARG is executed on exit from the shell.  If a SIGNAL_SPEC
-is DEBUG, ARG is executed after every simple command.  If the`-p' option
-is supplied then the trap commands associated with each SIGNAL_SPEC are
-displayed.  If no arguments are supplied or if only `-p' is given, trap
-prints the list of commands associated with each signal.  Each SIGNAL_SPEC
-is either a signal name in <signal.h> or a signal number.  Signal names
-are case insensitive and the SIG prefix is optional.  `trap -l' prints
-a list of signal names and their corresponding numbers.  Note that a
-signal can be sent to the shell with "kill -signal $$".
+shell and by the commands it invokes.
+
+If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell.  If
+a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command.
+
+If no arguments are supplied, trap prints the list of commands associated
+with each signal.
+
+Options:
+  -l   print a list of signal names and their corresponding numbers
+  -p   display the trap commands associated with each SIGNAL_SPEC
+
+Each SIGNAL_SPEC is either a signal name in <signal.h> or a signal number.
+Signal names are case insensitive and the SIG prefix is optional.  A
+signal may be sent to the shell with "kill -signal $$".
+
+Exit Status:
+Returns success unless a SIGSPEC is invalid or an invalid option is given.
 $END
 
 #include <config.h>
 $END
 
 #include <config.h>
@@ -87,7 +99,7 @@ int
 trap_builtin (list)
      WORD_LIST *list;
 {
 trap_builtin (list)
      WORD_LIST *list;
 {
-  int list_signal_names, display, result, opt, first_signal;
+  int list_signal_names, display, result, opt;
 
   list_signal_names = display = 0;
   result = EXECUTION_SUCCESS;
 
   list_signal_names = display = 0;
   result = EXECUTION_SUCCESS;
@@ -112,9 +124,9 @@ trap_builtin (list)
   opt = DSIG_NOCASE|DSIG_SIGPREFIX;    /* flags for decode_signal */
 
   if (list_signal_names)
   opt = DSIG_NOCASE|DSIG_SIGPREFIX;    /* flags for decode_signal */
 
   if (list_signal_names)
-    return (display_signal_list ((WORD_LIST *)NULL, 1));
+    return (sh_chkwrite (display_signal_list ((WORD_LIST *)NULL, 1)));
   else if (display || list == 0)
   else if (display || list == 0)
-    return (display_traps (list));
+    return (sh_chkwrite (display_traps (list)));
   else
     {
       char *first_arg;
   else
     {
       char *first_arg;
@@ -124,7 +136,10 @@ trap_builtin (list)
       first_arg = list->word->word;
       first_signal = first_arg && *first_arg && all_digits (first_arg) && signal_object_p (first_arg, opt);
 
       first_arg = list->word->word;
       first_signal = first_arg && *first_arg && all_digits (first_arg) && signal_object_p (first_arg, opt);
 
-      /* Backwards compatibility */
+      /* Backwards compatibility.  XXX - question about whether or not we
+        should throw an error if an all-digit argument doesn't correspond
+        to a valid signal number (e.g., if it's `50' on a system with only
+        32 signals).  */
       if (first_signal)
        operation = REVERT;
       /* When in posix mode, the historical behavior of looking for a
       if (first_signal)
        operation = REVERT;
       /* When in posix mode, the historical behavior of looking for a
@@ -176,7 +191,7 @@ trap_builtin (list)
                        if (interactive)
                          set_signal_handler (SIGINT, sigint_sighandler);
                        else
                        if (interactive)
                          set_signal_handler (SIGINT, sigint_sighandler);
                        else
-                         set_signal_handler (SIGINT, termination_unwind_protect);
+                         set_signal_handler (SIGINT, termsig_sighandler);
                        break;
 
                      case SIGQUIT:
                        break;
 
                      case SIGQUIT:
@@ -214,7 +229,6 @@ showtrap (i)
   char *t, *p, *sn;
 
   p = trap_list[i];
   char *t, *p, *sn;
 
   p = trap_list[i];
-
   if (p == (char *)DEFAULT_SIG)
     return;
 
   if (p == (char *)DEFAULT_SIG)
     return;