Reverse a decision made when the printsignals() routines from
kill and sh were merged so that the shell (for trap -l) and kill (for kill -l) can use the same routine, and site that function in the shell, rather than in kill (use the code that is in kill as the basis for that routine). This allows access to sh internals, and in particular to the posix option, so the builtin kill can operate in posix mode where the standard requires just a single character (space of newline) between successive signal names (and we prefer nicely aligned columns instead).. In a SMALL shell, use the ancient sh printsignals routine instead, it is smaller (and very much dumber). /bin/kill still uses the routine that is in its source, and is not posix compliant. A task for some other day...
This commit is contained in:
parent
3a1a1fef8c
commit
af2cfdd7cf
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $ */
|
||||
/* $NetBSD: kill.c,v 1.30 2018/12/12 20:22:43 kre Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $");
|
||||
__RCSID("$NetBSD: kill.c,v 1.30 2018/12/12 20:22:43 kre Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -254,6 +254,7 @@ nosig(const char *name)
|
|||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
#ifndef SHELL
|
||||
/*
|
||||
* Print the names of all the signals (neatly) to fp
|
||||
* "len" gives the number of chars already printed to
|
||||
|
@ -302,6 +303,7 @@ printsignals(FILE *fp, int len)
|
|||
if (len != 0)
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: sh.1,v 1.215 2018/12/12 12:56:17 kre Exp $
|
||||
.\" $NetBSD: sh.1,v 1.216 2018/12/12 20:22:43 kre Exp $
|
||||
.\" Copyright (c) 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
|
@ -530,11 +530,16 @@ whether a colon (:) terminates the user name in tilde (~) expansions
|
|||
other than in assignment statements
|
||||
.Dq ( no
|
||||
in posix mode),
|
||||
the format of the output of the
|
||||
.Ic kill Fl l
|
||||
command, where posix mode causes the names of the signals
|
||||
be separated by either a single space or newline, and where otherwise
|
||||
sufficient spaces are inserted to generate nice looking columns,
|
||||
and whether the shell treats
|
||||
an empty brace-list compound statement as a syntax error
|
||||
(expected by POSIX) or permits it.
|
||||
Such statements
|
||||
.Dq "{ }"
|
||||
.Dq "{\ }"
|
||||
can be useful when defining dummy functions.
|
||||
Lastly, in posix mode, only one
|
||||
.Dq \&!
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: trap.c,v 1.49 2018/12/05 22:25:38 kre Exp $ */
|
||||
/* $NetBSD: trap.c,v 1.50 2018/12/12 20:22:43 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.49 2018/12/05 22:25:38 kre Exp $");
|
||||
__RCSID("$NetBSD: trap.c,v 1.50 2018/12/12 20:22:43 kre Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -46,7 +46,11 @@ __RCSID("$NetBSD: trap.c,v 1.49 2018/12/05 22:25:38 kre Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
#undef CEOF /* from <termios.h> but concflicts with sh use */
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include "shell.h"
|
||||
|
@ -135,7 +139,7 @@ trap_signame(int signo)
|
|||
return nbuf;
|
||||
}
|
||||
|
||||
#if 0 /* Share the version of this in src/bin/kill/kill.c */
|
||||
#ifdef SMALL
|
||||
/*
|
||||
* Print a list of valid signal names
|
||||
*/
|
||||
|
@ -154,7 +158,62 @@ printsignals(struct output *out, int len)
|
|||
outc(' ', out);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else /* !SMALL */
|
||||
/*
|
||||
* 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(struct output *out, int len)
|
||||
{
|
||||
int sig;
|
||||
int nl, pad;
|
||||
const char *name;
|
||||
int termwidth = 80;
|
||||
|
||||
if ((name = bltinlookup("COLUMNS", 1)) != NULL)
|
||||
termwidth = (int)strtol(name, NULL, 10);
|
||||
else if (isatty(1)) {
|
||||
struct winsize win;
|
||||
|
||||
if (ioctl(1, TIOCGWINSZ, &win) == 0 && win.ws_col > 0)
|
||||
termwidth = win.ws_col;
|
||||
}
|
||||
|
||||
if (posix)
|
||||
pad = 1;
|
||||
else
|
||||
pad = (len | 7) + 1 - len;
|
||||
|
||||
for (sig = 0; (sig = signalnext(sig)) != 0; ) {
|
||||
name = signalname(sig);
|
||||
if (name == NULL)
|
||||
continue;
|
||||
|
||||
nl = strlen(name);
|
||||
|
||||
if (len > 0 && nl + len + pad >= termwidth) {
|
||||
outc('\n', out);
|
||||
len = 0;
|
||||
pad = 0;
|
||||
} else if (pad > 0 && len != 0)
|
||||
outfmt(out, "%*s", pad, "");
|
||||
else
|
||||
pad = 0;
|
||||
|
||||
len += nl + pad;
|
||||
if (!posix)
|
||||
pad = (nl | 7) + 1 - nl;
|
||||
else
|
||||
pad = 1;
|
||||
|
||||
outstr(name, out);
|
||||
}
|
||||
if (len != 0)
|
||||
outc('\n', out);
|
||||
}
|
||||
#endif /* SMALL */
|
||||
|
||||
/*
|
||||
* The trap builtin.
|
||||
|
|
Loading…
Reference in New Issue