From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14704 invoked from network); 8 Aug 2005 18:15:39 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Aug 2005 18:15:39 -0000 Received: (qmail 12692 invoked from network); 8 Aug 2005 18:15:33 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:15:33 -0000 Received: (qmail 5306 invoked by alias); 8 Aug 2005 18:15:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21581 Received: (qmail 5296 invoked from network); 8 Aug 2005 18:15:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Aug 2005 18:15:30 -0000 Received: (qmail 12404 invoked from network); 8 Aug 2005 18:15:30 -0000 Received: from mail.gmx.net (213.165.64.20) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:15:26 -0000 Received: (qmail invoked by alias); 08 Aug 2005 18:15:21 -0000 Received: from Bc93f.b.pppool.de (EHLO pcdahl4201) [213.7.201.63] by mail.gmx.net (mp008) with SMTP; 08 Aug 2005 20:15:21 +0200 X-Authenticated: #21620914 Message-ID: <029301c59c46$5cb47020$cc74fea9@pcdahl4201> From: "Thorsten Dahlheimer" To: Subject: PATCH: Better diagnostics and docs for trap builtin Date: Mon, 8 Aug 2005 20:24:04 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_028C_01C59C57.1F4301A0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Y-GMX-Trusted: 0 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00, MIME_QP_LONG_LINE autolearn=ham version=3.0.4 This is a multi-part message in MIME format. ------=_NextPart_000_028C_01C59C57.1F4301A0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_028C_01C59C57.1F4301A0 Content-Type: application/octet-stream; name="trap.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="trap.patch" Index: Doc/Zsh/builtins.yo=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v=0A= retrieving revision 1.78=0A= diff -u -p -r1.78 builtins.yo=0A= --- Doc/Zsh/builtins.yo 1 Jun 2005 10:45:41 -0000 1.78=0A= +++ Doc/Zsh/builtins.yo 8 Aug 2005 14:44:38 -0000=0A= @@ -1154,16 +1154,24 @@ and for processes run from the shell.=0A= findex(trap)=0A= cindex(signals, trapping)=0A= cindex(trapping signals)=0A= -item(tt(trap) [ var(arg) [ var(sig) ... ] ])(=0A= +item(tt(trap) [ var(arg) ] [ var(sig) ... ])(=0A= var(arg) is a series of commands (usually quoted to protect it from=0A= immediate evaluation by the shell) to be read and executed when the = shell=0A= -receives var(sig). Each var(sig) can be given as a number,=0A= -or as the name of a signal either with or without the string tt(SIG)=0A= +receives any of the signals var(sig). Each var(sig) can be given as a=0A= +number, or as the name of a signal either with or without the string = tt(SIG)=0A= in front.=0A= -If var(arg) is `tt(-)', then all traps var(sig) are reset to their=0A= +If var(arg) is `tt(-)', then the traps var(sig) are reset to their=0A= default values. If var(arg) is the empty string, then this signal=0A= is ignored by the shell and by the commands it invokes.=0A= =0A= +If var(sig) is omitted and var(arg) is `tt(-)', then all traps are reset=0A= +to their defaults. If var(arg) is omitted (i.e., the first argument is=0A= +a valid signal number or name), the effect is the same as if var(arg)=0A= +were `tt(-)'.=0A= +=0A= +The tt(trap) command with no arguments prints a list of commands=0A= +associated with each signal.=0A= +=0A= If var(sig) is tt(ZERR) then var(arg) will be executed=0A= after each command with a nonzero exit status. tt(ERR) is an alias=0A= for tt(ZERR) on systems that have no tt(SIGERR) signal (this is the=0A= @@ -1177,10 +1185,7 @@ If var(sig) is tt(0) or tt(EXIT)=0A= and the tt(trap) statement is not executed inside the body of a = function,=0A= then the command var(arg) is executed when the shell terminates.=0A= =0A= -tt(ZERR), tt(DEBUG) and tt(EXIT) traps are not executed inside other = traps.=0A= -=0A= -The tt(trap) command with no arguments prints a list of commands=0A= -associated with each signal.=0A= +tt(ZERR), tt(DEBUG), and tt(EXIT) traps are not executed inside other = traps.=0A= =0A= Note that traps defined with the tt(trap) builtin are slightly different=0A= from those defined as `tt(TRAP)var(NAL) () { ... }', as the latter have=0A= Index: Src/builtin.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v=0A= retrieving revision 1.143=0A= diff -u -p -r1.143 builtin.c=0A= --- Src/builtin.c 1 Aug 2005 22:20:36 -0000 1.143=0A= +++ Src/builtin.c 8 Aug 2005 14:45:57 -0000=0A= @@ -5021,9 +5021,15 @@ bin_trap(char *name, char **argv, UNUSED=0A= for (sig =3D 0; sig < VSIGCOUNT; sig++)=0A= unsettrap(sig);=0A= else=0A= - while (*argv)=0A= - unsettrap(getsignum(*argv++));=0A= - return 0;=0A= + for (; *argv; argv++) {=0A= + sig =3D getsignum(*argv);=0A= + if (sig =3D=3D -1) {=0A= + zwarnnam(name, "undefined signal: %s", *argv, 0);=0A= + break;=0A= + }=0A= + unsettrap(sig);=0A= + }=0A= + return *argv !=3D NULL;=0A= }=0A= =0A= /* Sort out the command to execute on trap */=0A= ------=_NextPart_000_028C_01C59C57.1F4301A0--