zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Better diagnostics and docs for trap builtin
@ 2005-08-08 18:24 Thorsten Dahlheimer
  2005-08-09  7:12 ` Wayne Davison
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Dahlheimer @ 2005-08-08 18:24 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 438 bytes --]

The trap builtin silently ignores invalid signal specifications
if the first argument is "-"; e.g.,

    % trap - INT '@#?junk!*' TERM 

succeeds without complaint.  The attached patch changes this so
that an error is reported (which matches the behaviour if the first
argument is not "-").
I've also amended the documentation for trap, which didn't discuss
the invocations "trap -" and "trap SIG1 SIG2 ...".

Regards,
Thorsten Dahlheimer

[-- Attachment #2: trap.patch --]
[-- Type: application/octet-stream, Size: 3173 bytes --]

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.78
diff -u -p -r1.78 builtins.yo
--- Doc/Zsh/builtins.yo	1 Jun 2005 10:45:41 -0000	1.78
+++ Doc/Zsh/builtins.yo	8 Aug 2005 14:44:38 -0000
@@ -1154,16 +1154,24 @@ and for processes run from the shell.
 findex(trap)
 cindex(signals, trapping)
 cindex(trapping signals)
-item(tt(trap) [ var(arg) [ var(sig) ... ] ])(
+item(tt(trap) [ var(arg) ] [ var(sig) ... ])(
 var(arg) is a series of commands (usually quoted to protect it from
 immediate evaluation by the shell) to be read and executed when the shell
-receives var(sig).  Each var(sig) can be given as a number,
-or as the name of a signal either with or without the string tt(SIG)
+receives any of the signals var(sig).  Each var(sig) can be given as a
+number, or as the name of a signal either with or without the string tt(SIG)
 in front.
-If var(arg) is `tt(-)', then all traps var(sig) are reset to their
+If var(arg) is `tt(-)', then the traps var(sig) are reset to their
 default values.  If var(arg) is the empty string, then this signal
 is ignored by the shell and by the commands it invokes.
 
+If var(sig) is omitted and var(arg) is `tt(-)', then all traps are reset
+to their defaults.  If var(arg) is omitted (i.e., the first argument is
+a valid signal number or name), the effect is the same as if var(arg)
+were `tt(-)'.
+
+The tt(trap) command with no arguments prints a list of commands
+associated with each signal.
+
 If var(sig) is tt(ZERR) then var(arg) will be executed
 after each command with a nonzero exit status.  tt(ERR) is an alias
 for tt(ZERR) on systems that have no tt(SIGERR) signal (this is the
@@ -1177,10 +1185,7 @@ If var(sig) is tt(0) or tt(EXIT)
 and the tt(trap) statement is not executed inside the body of a function,
 then the command var(arg) is executed when the shell terminates.
 
-tt(ZERR), tt(DEBUG) and tt(EXIT) traps are not executed inside other traps.
-
-The tt(trap) command with no arguments prints a list of commands
-associated with each signal.
+tt(ZERR), tt(DEBUG), and tt(EXIT) traps are not executed inside other traps.
 
 Note that traps defined with the tt(trap) builtin are slightly different
 from those defined as `tt(TRAP)var(NAL) () { ... }', as the latter have
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.143
diff -u -p -r1.143 builtin.c
--- Src/builtin.c	1 Aug 2005 22:20:36 -0000	1.143
+++ Src/builtin.c	8 Aug 2005 14:45:57 -0000
@@ -5021,9 +5021,15 @@ bin_trap(char *name, char **argv, UNUSED
 	    for (sig = 0; sig < VSIGCOUNT; sig++)
 		unsettrap(sig);
 	else
-	    while (*argv)
-		unsettrap(getsignum(*argv++));
-	return 0;
+	    for (; *argv; argv++) {
+		sig = getsignum(*argv);
+		if (sig == -1) {
+		    zwarnnam(name, "undefined signal: %s", *argv, 0);
+		    break;
+		}
+		unsettrap(sig);
+	    }
+	return *argv != NULL;
     }
 
     /* Sort out the command to execute on trap */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: Better diagnostics and docs for trap builtin
  2005-08-08 18:24 PATCH: Better diagnostics and docs for trap builtin Thorsten Dahlheimer
@ 2005-08-09  7:12 ` Wayne Davison
  0 siblings, 0 replies; 2+ messages in thread
From: Wayne Davison @ 2005-08-09  7:12 UTC (permalink / raw)
  To: Thorsten Dahlheimer; +Cc: zsh-workers

On Mon, Aug 08, 2005 at 08:24:04PM +0200, Thorsten Dahlheimer wrote:
> The trap builtin silently ignores invalid signal specifications
> if the first argument is "-";

Thanks -- I checked in your changes in after tweaking the trap docs
a little more.

..wayne..


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-09  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-08 18:24 PATCH: Better diagnostics and docs for trap builtin Thorsten Dahlheimer
2005-08-09  7:12 ` Wayne Davison

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).