Module Name: src Committed By: kre Date: Sun Oct 28 18:26:52 UTC 2018
Modified Files: src/bin/kill: kill.c src/bin/sh: trap.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/bin/kill/kill.c cvs rdiff -u -r1.45 -r1.46 src/bin/sh/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/kill/kill.c diff -u src/bin/kill/kill.c:1.28 src/bin/kill/kill.c:1.29 --- src/bin/kill/kill.c:1.28 Mon Jun 26 22:09:16 2017 +++ src/bin/kill/kill.c Sun Oct 28 18:26:52 2018 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #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 @@ int killcmd(int, char *argv[]); #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 @@ main(int argc, char *argv[]) printf("%s\n", sn); exit(0); } - printsignals(stdout); + printsignals(stdout, 0); exit(0); case 's': @@ -249,16 +249,21 @@ nosig(const char *name) { 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 @@ printsignals(FILE *fp) 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; Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.45 src/bin/sh/trap.c:1.46 --- src/bin/sh/trap.c:1.45 Sun Aug 19 23:50:27 2018 +++ src/bin/sh/trap.c Sun Oct 28 18:26:52 2018 @@ -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 @@ volatile int pendingsigs; /* indicates s 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 @@ signame_to_signum(const char *p) 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 @@ STATIC const char * 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 @@ trapcmd(int argc, char **argv) ap = argv + 1; if (argc == 2 && strcmp(*ap, "-l") == 0) { - printsignals(); + out1str("EXIT"); + printsignals(out1, 4); return 0; } if (argc == 2 && strcmp(*ap, "-") == 0) {