svn commit: r334920 - head/usr.bin/top
Eitan Adler
eadler at FreeBSD.org
Sun Jun 10 09:00:05 UTC 2018
Author: eadler
Date: Sun Jun 10 09:00:01 2018
New Revision: 334920
URL: https://svnweb.freebsd.org/changeset/base/334920
Log:
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).
Deleted:
head/usr.bin/top/sigconv.awk
Modified:
head/usr.bin/top/Makefile
head/usr.bin/top/commands.c
Modified: head/usr.bin/top/Makefile
==============================================================================
--- head/usr.bin/top/Makefile Sun Jun 10 08:59:57 2018 (r334919)
+++ head/usr.bin/top/Makefile Sun Jun 10 09:00:01 2018 (r334920)
@@ -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>
Modified: head/usr.bin/top/commands.c
==============================================================================
--- head/usr.bin/top/commands.c Sun Jun 10 08:59:57 2018 (r334919)
+++ head/usr.bin/top/commands.c Sun Jun 10 09:00:01 2018 (r334920)
@@ -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_
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);
}
More information about the svn-src-all
mailing list