Source-Changes-HG archive

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

[src/trunk]: src/bin Switch from using two printsignals() functions, one in t...



details:   https://anonhg.NetBSD.org/src/rev/8ec59e1180aa
branches:  trunk
changeset: 445427:8ec59e1180aa
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Oct 28 18:26:52 2018 +0000

description:
Switch from using two printsignals() functions, one in trap.c
and one in (the included from bin/kill) kill.c and use just
the one in kill.c (which is amended slightly so it can work
the way that trap.c needs it to work).    This one is chosen as
it was a much nicer implementation, and because while kill is
always built into the shell, kill also exists without the shell.

Leave the old implementation #if 0'd in trap.c (but updated to
match the calling convention of the one in kill.c) - for now.

Delete references of sys_signame[] from sh/trap.c and along with
that several uses of NSIG (unfortunately, there are still more)
and replace them with the newer libc functional interfaces.

diffstat:

 bin/kill/kill.c |  25 ++++++++++++++++---------
 bin/sh/trap.c   |  40 ++++++++++++++++++++--------------------
 2 files changed, 36 insertions(+), 29 deletions(-)

diffs (175 lines):

diff -r 6d35e8f63e00 -r 8ec59e1180aa bin/kill/kill.c
--- a/bin/kill/kill.c   Sun Oct 28 18:16:01 2018 +0000
+++ b/bin/kill/kill.c   Sun Oct 28 18:26:52 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kill.c,v 1.28 2017/06/26 22:09:16 kre Exp $ */
+/* $NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $ */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)kill.c     8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kill.c,v 1.28 2017/06/26 22:09:16 kre Exp $");
+__RCSID("$NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,7 +64,7 @@
 #endif /* SHELL */ 
 
 __dead static void nosig(const char *);
-static void printsignals(FILE *);
+void printsignals(FILE *, int);
 static int signum(const char *);
 static pid_t processnum(const char *);
 __dead static void usage(void);
@@ -115,7 +115,7 @@
                                printf("%s\n", sn);
                                exit(0);
                        }
-                       printsignals(stdout);
+                       printsignals(stdout, 0);
                        exit(0);
 
                case 's':
@@ -249,16 +249,21 @@
 {
 
        warnx("unknown signal %s; valid signals:", name);
-       printsignals(stderr);
+       printsignals(stderr, 0);
        exit(1);
        /* NOTREACHED */
 }
 
-static void
-printsignals(FILE *fp)
+/*
+ * Print the names of all the signals (neatly) to fp
+ * "len" gives the number of chars already printed to
+ * the current output line (in kill.c, always 0)
+ */
+void
+printsignals(FILE *fp, int len)
 {
        int sig;
-       int len, nl, pad;
+       int nl, pad;
        const char *name;
        int termwidth = 80;
 
@@ -271,7 +276,9 @@
                        termwidth = win.ws_col;
        }
 
-       for (pad = 0, len = 0, sig = 0; (sig = signalnext(sig)) != 0; ) {
+       pad = (len | 7) + 1 - len;
+
+       for (sig = 0; (sig = signalnext(sig)) != 0; ) {
                name = signalname(sig);
                if (name == NULL)
                        continue;
diff -r 6d35e8f63e00 -r 8ec59e1180aa bin/sh/trap.c
--- a/bin/sh/trap.c     Sun Oct 28 18:16:01 2018 +0000
+++ b/bin/sh/trap.c     Sun Oct 28 18:26:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.45 2018/08/19 23:50:27 kre Exp $    */
+/*     $NetBSD: trap.c,v 1.46 2018/10/28 18:26:52 kre Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)trap.c     8.5 (Berkeley) 6/5/95";
 #else
-__RCSID("$NetBSD: trap.c,v 1.45 2018/08/19 23:50:27 kre Exp $");
+__RCSID("$NetBSD: trap.c,v 1.46 2018/10/28 18:26:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -83,6 +83,7 @@
 
 static int getsigaction(int, sig_t *);
 STATIC const char *trap_signame(int);
+void printsignals(struct output *, int);
 
 /*
  * return the signal number described by `p' (as a number or a name)
@@ -100,13 +101,10 @@
        if (strcasecmp(p, "exit") == 0 )
                return 0;
        
-       if (strncasecmp(p, "sig", 3) == 0)
-               p += 3;
-
-       for (i = 0; i < NSIG; ++i)
-               if (strcasecmp (p, sys_signame[i]) == 0)
-                       return i;
-       return -1;
+       i = signalnumber(p);
+       if (i == 0)
+               i = -1;
+       return i;
 }
 
 /*
@@ -116,36 +114,37 @@
 trap_signame(int signo)
 {
        static char nbuf[12];
-       const char *p = NULL;
+       const char *p;
 
        if (signo == 0)
                return "EXIT";
-       if (signo > 0 && signo < NSIG)
-               p = sys_signame[signo];
+       p = signalname(signo);
        if (p != NULL)
                return p;
        (void)snprintf(nbuf, sizeof nbuf, "%d", signo);
        return nbuf;
 }
 
+#if 0          /* Share the version of this in src/bin/kill/kill.c */
 /*
  * Print a list of valid signal names
  */
-static void
-printsignals(void)
+void
+printsignals(struct output *out, int len)
 {
        int n;
 
-       out1str("EXIT ");
-
+       if (len != 0)
+               outc(' ', out);
        for (n = 1; n < NSIG; n++) {
-               out1fmt("%s", trap_signame(n));
+               outfmt(out, "%s", trap_signame(n));
                if ((n == NSIG/2) ||  n == (NSIG - 1))
-                       out1str("\n");
+                       outstr("\n", out);
                else
-                       out1c(' ');
+                       outc(' ', out);
        }
 }
+#endif
 
 /*
  * The trap builtin.
@@ -163,7 +162,8 @@
        ap = argv + 1;
 
        if (argc == 2 && strcmp(*ap, "-l") == 0) {
-               printsignals();
+               out1str("EXIT");
+               printsignals(out1, 4);
                return 0;
        }
        if (argc == 2 && strcmp(*ap, "-") == 0) {



Home | Main Index | Thread Index | Old Index