zsh-workers
 help / color / mirror / code / Atom feed
* SUGGESTION: kill -l could show numbers, too
@ 2004-11-18 14:52 Christian Höltje
  2004-11-18 16:05 ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Höltje @ 2004-11-18 14:52 UTC (permalink / raw)
  To: zsh-workers

I have a suggestion for the kill builtin:

It would be nice if when you did '-l' to show the list of signal
that it show the signal number.  I saw this on a friends system
where it did the following:
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGBUS       8) SIGFPE
 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
13) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD
18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN
22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO
30) SIGPWR      31) SIGSYS      33) SIGRTMIN    34) SIGRTMIN+1
35) SIGRTMIN+2  36) SIGRTMIN+3  37) SIGRTMIN+4  38) SIGRTMIN+5
39) SIGRTMIN+6  40) SIGRTMIN+7  41) SIGRTMIN+8  42) SIGRTMIN+9
43) SIGRTMIN+10 44) SIGRTMIN+11 45) SIGRTMIN+12 46) SIGRTMIN+13
47) SIGRTMIN+14 48) SIGRTMIN+15 49) SIGRTMAX-15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7  58) SIGRTMAX-6
59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

I thought it was a keen feature.  I'm not sure listing everything
plus the kitchen sink is actually worthwhile, but if only for the
ones that show up by default in the current version.

Ciao!

-- 
...experience declares that man is the only animal which devours his own
kind, for I can apply no milder term to the governments of Europe, and to
the general prey of the rich on the poor.
		-- Thomas Jefferson to Edward Carrington, 16 Jan 1787

The Doctor What: Da Man                          http://docwhat.gerf.org/
docwhat *at* gerf *dot* org                                        KF6VNC

Outgoing mail is certified Virus Free.
Checked by Debian GNU/Linux (http://www.debian.org).
Version: 3.0  / 9368 out of 12296 packages installed


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

* Re: SUGGESTION: kill -l could show numbers, too
  2004-11-18 14:52 SUGGESTION: kill -l could show numbers, too Christian Höltje
@ 2004-11-18 16:05 ` Peter Stephenson
  2004-11-18 16:12   ` Dan Nelson
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Peter Stephenson @ 2004-11-18 16:05 UTC (permalink / raw)
  To: zsh-workers

Christian =?iso-8859-1?Q?H=F6ltje?= wrote:
> I have a suggestion for the kill builtin:
> 
> It would be nice if when you did '-l' to show the list of signal
> that it show the signal number.

Not quite as convenient, but try this function:

kill-l() {
  for i in {1..$#signals}; do
    print $((i-1))\) SIG$signals[$i]
  done | pr -t5
}

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: SUGGESTION: kill -l could show numbers, too
  2004-11-18 16:05 ` Peter Stephenson
@ 2004-11-18 16:12   ` Dan Nelson
  2004-11-18 16:33   ` Bart Schaefer
  2004-11-18 16:39   ` SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD) Stephane Chazelas
  2 siblings, 0 replies; 11+ messages in thread
From: Dan Nelson @ 2004-11-18 16:12 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

In the last episode (Nov 18), Peter Stephenson said:
> Christian =?iso-8859-1?Q?H=F6ltje?= wrote:
> > I have a suggestion for the kill builtin:
> > 
> > It would be nice if when you did '-l' to show the list of signal
> > that it show the signal number.
> 
> Not quite as convenient, but try this function:
> 
> kill-l() {
>   for i in {1..$#signals}; do
>     print $((i-1))\) SIG$signals[$i]
>   done | pr -t5
> }

You probably want to strip ZERR and DEBUG out of that list beforehand :)

-- 
	Dan Nelson
	dnelson@allantgroup.com


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

* Re: SUGGESTION: kill -l could show numbers, too
  2004-11-18 16:05 ` Peter Stephenson
  2004-11-18 16:12   ` Dan Nelson
@ 2004-11-18 16:33   ` Bart Schaefer
  2004-11-18 16:50     ` Stephane Chazelas
  2004-11-18 16:39   ` SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD) Stephane Chazelas
  2 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2004-11-18 16:33 UTC (permalink / raw)
  To: zsh-workers

On Thu, 18 Nov 2004, Peter Stephenson wrote:

> kill-l() {
>   for i in {1..$#signals}; do
>     print $((i-1))\) SIG$signals[$i]
>   done | pr -t5
> }

Which can be rewritten as a wrapper, and without the pipe to "pr":

  kill() {
    case $1 in
    (-l)
      integer i=0
      print -c ${(e)signals//*/\$((i++))\) SIG\$signals[\$i]}
      ;;
    (*)
      command kill "$@"
      ;;
    esac
  }


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-18 16:05 ` Peter Stephenson
  2004-11-18 16:12   ` Dan Nelson
  2004-11-18 16:33   ` Bart Schaefer
@ 2004-11-18 16:39   ` Stephane Chazelas
  2004-11-18 17:22     ` Peter Stephenson
  2 siblings, 1 reply; 11+ messages in thread
From: Stephane Chazelas @ 2004-11-18 16:39 UTC (permalink / raw)
  To: zsh-workers

On Thu, Nov 18, 2004 at 04:05:17PM +0000, Peter Stephenson wrote:
> Christian =?iso-8859-1?Q?H=F6ltje?= wrote:
> > I have a suggestion for the kill builtin:
> > 
> > It would be nice if when you did '-l' to show the list of signal
> > that it show the signal number.
> 
> Not quite as convenient, but try this function:
> 
> kill-l() {
>   for i in {1..$#signals}; do
>     print $((i-1))\) SIG$signals[$i]
>   done | pr -t5
> }
[...]

Or, to avoid "pr":

kill-l () {
        local -a s
        for i in {1..$#signals}
        do
                s[i]="$((i-1))) SIG$signals[$i]"
        done
        print -C5 $s
}

BTW, I noted some discrepancies on the result of kill -l between
various shells and /bin/kill on that Linux-i386:

bash    bin     csh     dash    ksh     pdksh   zsh     

ABRT    ABRT    ABRT    ABRT    IOT     ABRT    ABRT
        STKFLT  STKFLT  16      SIG16   STKFLT  STKFLT
CHLD    CHLD    CHLD    CHLD    CHLD    CHLD    CLD
IO      POLL    POLL    IO      POLL    IO      POLL
SYS     SYS     SYS     SYS     SYS     UNUSED  SYS


Why SIGCLD and not SIGCHLD for zsh?

SUSv3 (POSIX) seems to require SIGCHLD
http://www.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html

-- 
Stéphane


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

* Re: SUGGESTION: kill -l could show numbers, too
  2004-11-18 16:33   ` Bart Schaefer
@ 2004-11-18 16:50     ` Stephane Chazelas
  0 siblings, 0 replies; 11+ messages in thread
From: Stephane Chazelas @ 2004-11-18 16:50 UTC (permalink / raw)
  To: zsh-workers

On Thu, Nov 18, 2004 at 08:33:04AM -0800, Bart Schaefer wrote:
[...]
> Which can be rewritten as a wrapper, and without the pipe to "pr":
> 
>   kill() {
>     case $1 in
>     (-l)
>       integer i=0
>       print -c ${(e)signals//*/\$((i++))\) SIG\$signals[\$i]}
>       ;;
>     (*)
>       command kill "$@"
[...]

Rather:

builtin kill "$@"

And you need to check the number of arguments (for kill -l TERM
for instance)

kill() {
  if (( $# == 1 )) && [[ $1 = "-l" ]]; then
    integer i=0
    print -rc ${(e)signals//*/\$((i++))\) SIG\$signals[\$i]}
  else
    builtin kill "$@"
  fi
}

-- 
Stephane


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-18 16:39   ` SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD) Stephane Chazelas
@ 2004-11-18 17:22     ` Peter Stephenson
  2004-11-19  9:59       ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2004-11-18 17:22 UTC (permalink / raw)
  To: zsh-workers

Stephane Chazelas wrote:
> Why SIGCLD and not SIGCHLD for zsh?

It's an artefact of this sort of thing in header files:

#define	SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
#define	SIGCHLD		17	/* Child status has changed (POSIX).  */

We pick the first one, assuming that's to be preferred.

The following explicitly prefers SIGCHLD.  Any other multiple signals
can be handled similarly.  I'm not sure about SIGPOLL.

Maybe we should think about mapping alternatives so that both kill -CLD
and kill -CHLD work.

Index: Src/signames2.awk
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signames2.awk,v
retrieving revision 1.3
diff -u -r1.3 signames2.awk
--- Src/signames2.awk	12 Mar 2004 09:59:24 -0000	1.3
+++ Src/signames2.awk	18 Nov 2004 17:15:22 -0000
@@ -12,6 +12,7 @@
     split(sigtail, tmp)
     signam = substr(tmp[1], 4, 20)
     signum = tmp[2]
+    if (signam == "CHLD" && sig[signum] == "CLD")  sig[signum] = ""
     if (sig[signum] == "") {
 	sig[signum] = signam
 	if (0 + max < 0 + signum && signum < 60)

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-18 17:22     ` Peter Stephenson
@ 2004-11-19  9:59       ` Peter Stephenson
  2004-11-19 15:34         ` Bart Schaefer
  2004-11-20 19:29         ` Peter Stephenson
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Stephenson @ 2004-11-19  9:59 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:
> The following explicitly prefers SIGCHLD.  Any other multiple signals
> can be handled similarly.  I'm not sure about SIGPOLL.

It looks like SIGPOLL is standardised, though from X/Open rather than
Posix, while SIGIO isn't (although it has a long history, too).  So I've
made it prefer SIGPOLL to SIGIO.  This doesn't actually change anything
on Linux.

I'm working on something to allow variants on input.  This is easy
enough for kill, the real killer is function-style traps.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-19  9:59       ` Peter Stephenson
@ 2004-11-19 15:34         ` Bart Schaefer
  2004-11-19 16:02           ` Peter Stephenson
  2004-11-20 19:29         ` Peter Stephenson
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2004-11-19 15:34 UTC (permalink / raw)
  To: zsh-workers

On Fri, 19 Nov 2004, Peter Stephenson wrote:

> made it prefer SIGPOLL to SIGIO.

If they don't have the same signal number, they still both appear, right?

> the real killer is function-style traps.

No pun intended.


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-19 15:34         ` Bart Schaefer
@ 2004-11-19 16:02           ` Peter Stephenson
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Stephenson @ 2004-11-19 16:02 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> On Fri, 19 Nov 2004, Peter Stephenson wrote:
> 
> > made it prefer SIGPOLL to SIGIO.
> 
> If they don't have the same signal number, they still both appear, right?

Yes, the test is looking for signals with the same number.

> > the real killer is function-style traps.
> 
> No pun intended.

Speak for yourself.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD)
  2004-11-19  9:59       ` Peter Stephenson
  2004-11-19 15:34         ` Bart Schaefer
@ 2004-11-20 19:29         ` Peter Stephenson
  1 sibling, 0 replies; 11+ messages in thread
From: Peter Stephenson @ 2004-11-20 19:29 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:
> I'm working on something to allow variants on input.  This is easy
> enough for kill, the real killer is function-style traps.

The following appears to be Not Completely Broken (TM), although I put
some weasel words into the documentation.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.71
diff -u -r1.71 builtins.yo
--- Doc/Zsh/builtins.yo	5 Oct 2004 10:39:43 -0000	1.71
+++ Doc/Zsh/builtins.yo	20 Nov 2004 19:10:32 -0000
@@ -626,6 +626,14 @@
 listed.  For each var(sig) that is a signal number or a number
 representing the exit status of a process which was terminated or
 stopped by a signal the name of the signal is printed.
+
+On some systems, alternative signal names are allowed for a few signals.
+Typical examples are tt(SIGCHLD) and tt(SIGCLD) or tt(SIGPOLL) and
+tt(SIGIO), assuming they correspond to the same signal number.  tt(kill
+-l) will only list the preferred form, however tt(kill -l) var(alt) will
+show if the alternative form corresponds to a signal number.  For example,
+under Linux tt(kill -l IO) and tt(kill -l POLL) both output 29, hence
+tt(kill -IO) and tt(kill -POLL) have the same effect.
 )
 findex(let)
 item(tt(let) var(arg) ...)(
@@ -1179,6 +1187,11 @@
 example(TRAPDEBUG() { print $LINENO; })
 
 will always print the number zero.
+
+Alternative signal names are allowed as described under tt(kill) above.
+Defining a trap under either name causes any trap under an alternative
+name to be removed.  However, it is recommended that for consistency
+users stick exclusively to one name or another.
 )
 findex(true)
 cindex(doing nothing, successfully)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.131
diff -u -r1.131 builtin.c
--- Src/builtin.c	21 Oct 2004 00:33:50 -0000	1.131
+++ Src/builtin.c	20 Nov 2004 19:11:34 -0000
@@ -2543,7 +2543,16 @@
 		/* no flags, so just print */
 		shfunctab->printnode((HashNode) shf, pflags);
 	} else if (on & PM_UNDEFINED) {
-	    int signum, ok = 1;
+	    int signum = -1, ok = 1;
+
+	    if (!strncmp(*argv, "TRAP", 4) &&
+		(signum = getsignum(*argv + 4)) != -1) {
+		/*
+		 * Because of the possibility of alternative names,
+		 * we must remove the trap explicitly.
+		 */
+		removetrapnode(signum);
+	    }
 
 	    /* Add a new undefined (autoloaded) function to the *
 	     * hash table with the corresponding flags set.     */
@@ -2552,8 +2561,7 @@
 	    shf->funcdef = mkautofn(shf);
 	    shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
 
-	    if (!strncmp(*argv, "TRAP", 4) &&
-		(signum = getsignum(*argv + 4)) != -1) {
+	    if (signum != -1) {
 		if (settrap(signum, shf->funcdef)) {
 		    shfunctab->removenode(shfunctab, *argv);
 		    shfunctab->freenode((HashNode)shf);
@@ -4898,11 +4906,9 @@
 	queue_signals();
 	for (sig = 0; sig < VSIGCOUNT; sig++) {
 	    if (sigtrapped[sig] & ZSIG_FUNC) {
-		char fname[20];
 		HashNode hn;
 
-		sprintf(fname, "TRAP%s", sigs[sig]);
-		if ((hn = shfunctab->getnode(shfunctab, fname)))
+		if ((hn = gettrapnode(sig, 0)))
 		    shfunctab->printnode(hn, 0);
 		DPUTS(!hn, "BUG: I did not find any trap functions!");
 	    } else if (sigtrapped[sig]) {
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.77
diff -u -r1.77 exec.c
--- Src/exec.c	29 Oct 2004 10:14:34 -0000	1.77
+++ Src/exec.c	20 Nov 2004 19:12:13 -0000
@@ -3345,6 +3345,12 @@
 		return 1;
 	    }
 	    sigtrapped[signum] |= ZSIG_FUNC;
+
+	    /*
+	     * Remove the old node explicitly in case it has
+	     * an alternative name
+	     */
+	    removetrapnode(signum);
 	}
 	shfunctab->addnode(shfunctab, ztrdup(s), shf);
     }
Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.35
diff -u -r1.35 jobs.c
--- Src/jobs.c	22 Oct 2004 19:38:59 -0000	1.35
+++ Src/jobs.c	20 Nov 2004 19:12:34 -0000
@@ -1819,6 +1819,36 @@
     return retval;
 }
 
+#if defined(SIGCHLD) && defined(SIGCLD)
+#if SIGCHLD == SIGCLD
+#define ALT_SIGS 1
+#endif
+#endif
+#if defined(SIGPOLL) && defined(SIGIO)
+#if SIGPOLL == SIGIO
+#define ALT_SIGS 1
+#endif
+#endif
+
+#ifdef ALT_SIGS
+const struct {
+    const char *name;
+    int num;
+} alt_sigs[] = {
+#if defined(SIGCHLD) && defined(SIGCLD)
+#if SIGCHLD == SIGCLD
+    { "CLD", SIGCLD },
+#endif
+#endif
+#if defined(SIGPOLL) && defined(SIGIO)
+#if SIGPOLL == SIGIO
+    { "IO", SIGIO },
+#endif
+#endif
+    { NULL, 0 }
+};
+#endif
+
 /* kill: send a signal to a process.  The process(es) may be specified *
  * by job specifier (see above) or pid.  A signal, defaulting to       *
  * SIGTERM, may be specified by name or number, preceded by a dash.    */
@@ -1847,6 +1877,18 @@
 			    for (sig = 1; sig <= SIGCOUNT; sig++)
 				if (!cstrpcmp(sigs + sig, &signame))
 				    break;
+#ifdef ALT_SIGS
+			    if (sig > SIGCOUNT) {
+				int i;
+
+				for (i = 0; alt_sigs[i].name; i++)
+				    if (!cstrpcmp(&alt_sigs[i].name, &signame))
+				    {
+					sig = alt_sigs[i].num;
+					break;
+				    }
+			    }
+#endif
 			    if (sig > SIGCOUNT) {
 				zwarnnam(nam, "unknown signal: SIG%s",
 					 signame, 0);
@@ -1908,6 +1950,18 @@
 			break;
 		if (*signame == '0' && !signame[1])
 		    sig = 0;
+#ifdef ALT_SIGS
+		if (sig > SIGCOUNT) {
+		    int i;
+
+		    for (i = 0; alt_sigs[i].name; i++)
+			if (!strcmp(alt_sigs[i].name, signame))
+			{
+			    sig = alt_sigs[i].num;
+			    break;
+			}
+		}
+#endif
 		if (sig > SIGCOUNT) {
 		    zwarnnam(nam, "unknown signal: SIG%s", signame, 0);
 		    zwarnnam(nam, "type kill -l for a List of signals", NULL, 0);
@@ -1964,6 +2018,81 @@
 
     return returnval < 126 ? returnval : 1;
 }
+/* Get a signal number from a string */
+
+/**/
+mod_export int
+getsignum(char *s)
+{
+    int x, i;
+
+    /* check for a signal specified by number */
+    x = atoi(s);
+    if (idigit(*s) && x >= 0 && x < VSIGCOUNT)
+	return x;
+
+    /* search for signal by name */
+    for (i = 0; i < VSIGCOUNT; i++)
+	if (!strcmp(s, sigs[i]))
+	    return i;
+
+#ifdef ALT_SIGS
+    for (i = 0; alt_sigs[i].name; i++)
+    {
+	if (!strcmp(s, alt_sigs[i].name))
+	    return alt_sigs[i].num;
+    }
+#endif
+
+    /* no matching signal */
+    return -1;
+}
+
+/* Get the function node for a trap, taking care about alternative names */
+/**/
+HashNode
+gettrapnode(int sig, int ignoredisable)
+{
+    char fname[20];
+    HashNode hn;
+    HashNode (*getptr)(HashTable ht, char *name);
+#ifdef ALT_SIGS
+    int i;
+#endif
+    if (ignoredisable)
+	getptr = shfunctab->getnode2;
+    else
+	getptr = shfunctab->getnode;
+
+    sprintf(fname, "TRAP%s", sigs[sig]);
+    if ((hn = getptr(shfunctab, fname)))
+	return hn;
+
+#ifdef ALT_SIGS
+    for (i = 0; alt_sigs[i].name; i++) {
+	if (alt_sigs[i].num == sig) {
+	    sprintf(fname, "TRAP%s", alt_sigs[i].name);
+	    if ((hn = getptr(shfunctab, fname)))
+		return hn;
+	}
+    }
+#endif
+
+    return NULL;
+}
+
+/* Remove a TRAP function under any name for the signal */
+
+/**/
+void
+removetrapnode(int sig)
+{
+    HashNode hn = gettrapnode(sig, 1);
+    if (hn) {
+	shfunctab->removenode(shfunctab, hn->nam);
+	shfunctab->freenode(hn);
+    }
+}
 
 /* Suspend this shell */
 
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.32
diff -u -r1.32 signals.c
--- Src/signals.c	8 Oct 2004 14:37:31 -0000	1.32
+++ Src/signals.c	20 Nov 2004 19:12:44 -0000
@@ -697,10 +697,8 @@
 	 * Get the old function: this assumes we haven't added
 	 * the new one yet.
 	 */
-	char func[20];
 	Shfunc shf, newshf = NULL;
-	sprintf(func, "TRAP%s", sigs[sig]);
-	if ((shf = (Shfunc)shfunctab->getnode2(shfunctab, func))) {
+	if ((shf = (Shfunc)gettrapnode(sig, 1))) {
 	    /* Copy the node for saving */
 	    newshf = (Shfunc) zalloc(sizeof(*newshf));
 	    newshf->nam = ztrdup(shf->nam);
@@ -837,16 +835,15 @@
      * That causes a little inefficiency, but a good deal more reliability.
      */
     if (trapped & ZSIG_FUNC) {
-	char func[20];
-	HashNode node;
+	HashNode node = gettrapnode(sig, 1);
 
-	sprintf(func, "TRAP%s", sigs[sig]);
 	/*
 	 * As in dosavetrap(), don't call removeshfuncnode() because
 	 * that calls back into unsettrap();
 	 */
 	sigfuncs[sig] = NULL;
-	node = removehashnode(shfunctab, func);
+	if (node)
+	    removehashnode(shfunctab, node->nam);
 	unqueue_signals();
 
 	return node;
@@ -1010,10 +1007,10 @@
     runhookdef(BEFORETRAPHOOK, NULL);
     if (*sigtr & ZSIG_FUNC) {
 	int osc = sfcontext;
+	HashNode hn = gettrapnode(sig, 0);
 
 	args = znewlinklist();
-	name = (char *) zalloc(5 + strlen(sigs[sig]));
-	sprintf(name, "TRAP%s", sigs[sig]);
+	name = ztrdup(hn->nam);
 	zaddlinknode(args, name);
 	sprintf(num, "%d", sig);
 	zaddlinknode(args, num);
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.69
diff -u -r1.69 utils.c
--- Src/utils.c	21 Oct 2004 00:33:42 -0000	1.69
+++ Src/utils.c	20 Nov 2004 19:13:19 -0000
@@ -3969,27 +3969,6 @@
     return err;
 }
 
-/* Get a signal number from a string */
-
-/**/
-mod_export int
-getsignum(char *s)
-{
-    int x, i;
-
-    /* check for a signal specified by number */
-    x = atoi(s);
-    if (idigit(*s) && x >= 0 && x < VSIGCOUNT)
-	return x;
-
-    /* search for signal by name */
-    for (i = 0; i < VSIGCOUNT; i++)
-	if (!strcmp(s, sigs[i]))
-	    return i;
-
-    /* no matching signal */
-    return -1;
-}
 
 /* Check whether the shell is running with privileges in effect.  *
  * This is the case if EITHER the euid is zero, OR (if the system *

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


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

end of thread, other threads:[~2004-11-21  7:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-18 14:52 SUGGESTION: kill -l could show numbers, too Christian Höltje
2004-11-18 16:05 ` Peter Stephenson
2004-11-18 16:12   ` Dan Nelson
2004-11-18 16:33   ` Bart Schaefer
2004-11-18 16:50     ` Stephane Chazelas
2004-11-18 16:39   ` SUGGESTION: kill -l could show numbers, too (+CLD vs CHLD) Stephane Chazelas
2004-11-18 17:22     ` Peter Stephenson
2004-11-19  9:59       ` Peter Stephenson
2004-11-19 15:34         ` Bart Schaefer
2004-11-19 16:02           ` Peter Stephenson
2004-11-20 19:29         ` Peter Stephenson

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).