top(1): use sys_signame instead of hard coding signals

This enables the removal of the signal.h awk script. Shamelessly stolen
from kill(1).
This commit is contained in:
Eitan Adler 2018-06-10 09:00:01 +00:00
parent b26cf3d06c
commit 561b0720cf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334920
3 changed files with 17 additions and 74 deletions

View File

@ -4,7 +4,7 @@
PROG= top
SRCS= commands.c display.c machine.c screen.c top.c \
username.c utils.c sigdesc.h
username.c utils.c
CFLAGS+= -I ${.OBJDIR}
MAN= top.1
@ -19,10 +19,4 @@ NO_WERROR=
CFLAGS.clang=-Wno-error=incompatible-pointer-types-discards-qualifiers -Wno-error=cast-qual
LIBADD= ncursesw m kvm jail
CLEANFILES= sigdesc.h
SIGNAL_H= ${SRCTOP}/sys/sys/signal.h
sigdesc.h: sigconv.awk ${SIGNAL_H}
awk -f ${SRCTOP}/usr.bin/top/sigconv.awk < ${SIGNAL_H} > ${.TARGET}
.include <bsd.prog.mk>

View File

@ -30,7 +30,6 @@
#include <unistd.h>
#include "commands.h"
#include "sigdesc.h" /* generated automatically */
#include "top.h"
#include "machine.h"
@ -352,6 +351,20 @@ static const char invalid_signal_number[] = " invalid_signal_number";
static const char bad_signal_name[] = " bad signal name";
static const char bad_pri_value[] = " bad priority value";
static int
signame_to_signum(const char * sig)
{
int n;
if (strncasecmp(sig, "SIG", 3) == 0)
sig += 3;
for (n = 1; n < sys_nsig; n++) {
if (!strcasecmp(sys_signame[n], sig))
return (n);
}
return (-1);
}
/*
* kill_procs(str) - send signals to processes, much like the "kill"
* command does; invoked in response to 'k'.
@ -363,7 +376,6 @@ kill_procs(char *str)
char *nptr;
int signum = SIGTERM; /* default */
int procnum;
struct sigdesc *sigp;
int uid;
/* reset error array */
@ -393,18 +405,10 @@ kill_procs(char *str)
}
else
{
/* translate the name into a number */
for (sigp = sigdesc; sigp->name != NULL; sigp++)
{
if (strcasecmp(sigp->name, str + 1) == 0)
{
signum = sigp->number;
break;
}
}
signum = signame_to_signum(str + 1);
/* was it ever found */
if (sigp->name == NULL)
if (signum == -1 )
{
return(bad_signal_name);
}

View File

@ -1,55 +0,0 @@
# $FreeBSD$
BEGIN {
nsig = 0;
j = 0;
print "/* This file was automatically generated */"
print "/* by the awk script \"sigconv.awk\". */\n"
print "struct sigdesc {"
print " const char * const name;"
print " const int number;"
print "};\n"
print "static struct sigdesc sigdesc[] = {"
}
/^#define[ \t][ \t]*SIG[A-Z]+[0-9]*[ \t]/ {
j = sprintf("%d", $3);
str = $2;
if (nsig < j)
nsig = j;
siglist[j] = sprintf("{ \"%s\",\t%2d },", \
substr(str, 4), j);
}
/^#[ \t]*define[ \t][ \t]*SIG[A-Z]+[0-9]*[ \t]/ {
j = sprintf("%d", $4);
str = $3;
if (nsig < j)
nsig = j;
siglist[j] = sprintf("{ \"%s\",\t%2d },", \
substr(str, 4), j);
}
/^#[ \t]*define[ \t][ \t]*_SIG[A-Z]+[0-9]*[ \t]/ {
j = sprintf("%d", $4);
str = $3;
if (nsig < j)
nsig = j;
siglist[j] = sprintf("{ \"%s\",\t%2d },", \
substr(str, 5), j);
}
END {
for (n = 1; n <= nsig; n++)
if (siglist[n] != "")
printf(" %s\n", siglist[n]);
printf(" { NULL,\t 0 }\n};\n");
}