top(1): assume that we're building on FreeBSD
This allows us to avoid the ifdefs that we set unconditionally.
This commit is contained in:
parent
a4af6c0592
commit
946e91ab0c
@ -4,7 +4,7 @@ PROG= top
|
||||
SRCS= commands.c display.c machine.c screen.c top.c \
|
||||
username.c utils.c version.c
|
||||
SRCS+= sigdesc.h top.local.h
|
||||
CFLAGS+= -DHAVE_GETOPT -DHAVE_STRERROR -DORDER -I ${.OBJDIR}
|
||||
CFLAGS+= -I ${.OBJDIR}
|
||||
MAN= top.1
|
||||
|
||||
WARNS?= 1
|
||||
|
@ -86,7 +86,6 @@ J - display processes for only one jail (+ selects all jails)\n\
|
||||
k - kill processes; send a signal to a list of processes\n\
|
||||
m - toggle the display between 'cpu' and 'io' modes\n\
|
||||
n or # - change number of processes to display\n", stdout);
|
||||
#ifdef ORDER
|
||||
if (displaymode == DISP_CPU)
|
||||
fputs("\
|
||||
o - specify sort order (pri, size, res, cpu, time, threads, jid, pid)\n",
|
||||
@ -95,7 +94,6 @@ o - specify sort order (pri, size, res, cpu, time, threads, jid, pid)\n",
|
||||
fputs("\
|
||||
o - specify sort order (vcsw, ivcsw, read, write, fault, total, jid, pid)\n",
|
||||
stdout);
|
||||
#endif
|
||||
fputs("\
|
||||
P - toggle the displaying of per-CPU statistics\n\
|
||||
r - renice a process\n\
|
||||
|
@ -1220,7 +1220,6 @@ register char **names;
|
||||
register char *p;
|
||||
register int num;
|
||||
register char *thisname;
|
||||
register int useM = No;
|
||||
char rbuf[6];
|
||||
|
||||
/* format each number followed by its string */
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* "getopt" routine customized for top.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Many modern-day Unix implementations already have this function
|
||||
* in libc. The standard "getopt" is perfectly sufficient for top's
|
||||
* needs. If such a function exists in libc then you certainly don't
|
||||
* need to compile this one in. To prevent this function from being
|
||||
* compiled, define "HAVE_GETOPT". This is usually done in the "CFLAGS"
|
||||
* line of the corresponding machine module.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This empty declaration exists solely to placate overexhuberant C
|
||||
* compilers that like to warn you about content-free files.
|
||||
*/
|
||||
static void __empty();
|
||||
|
||||
#ifndef HAVE_GETOPT
|
||||
|
||||
/*LINTLIBRARY*/
|
||||
|
||||
#include "os.h"
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
#define ERR(s, c) if(opterr){\
|
||||
extern int write();\
|
||||
char errbuf[2];\
|
||||
errbuf[0] = c; errbuf[1] = '\n';\
|
||||
(void) write(2, argv[0], strlen(argv[0]));\
|
||||
(void) write(2, s, strlen(s));\
|
||||
(void) write(2, errbuf, 2);}
|
||||
|
||||
|
||||
int opterr = 1;
|
||||
int optind = 1;
|
||||
int optopt;
|
||||
char *optarg;
|
||||
|
||||
int
|
||||
getopt(argc, argv, opts)
|
||||
int argc;
|
||||
char **argv, *opts;
|
||||
{
|
||||
static int sp = 1;
|
||||
register int c;
|
||||
register char *cp;
|
||||
|
||||
if(sp == 1)
|
||||
if(optind >= argc ||
|
||||
argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
return(EOF);
|
||||
else if(strcmp(argv[optind], "--") == 0) {
|
||||
optind++;
|
||||
return(EOF);
|
||||
}
|
||||
optopt = c = argv[optind][sp];
|
||||
if(c == ':' || (cp=strchr(opts, c)) == NULL) {
|
||||
ERR(": unknown option, -", c);
|
||||
if(argv[optind][++sp] == '\0') {
|
||||
optind++;
|
||||
sp = 1;
|
||||
}
|
||||
return('?');
|
||||
}
|
||||
if(*++cp == ':') {
|
||||
if(argv[optind][sp+1] != '\0')
|
||||
optarg = &argv[optind++][sp+1];
|
||||
else if(++optind >= argc) {
|
||||
ERR(": argument missing for -", c);
|
||||
sp = 1;
|
||||
return('?');
|
||||
} else
|
||||
optarg = argv[optind++];
|
||||
sp = 1;
|
||||
} else {
|
||||
if(argv[optind][++sp] == '\0') {
|
||||
sp = 1;
|
||||
optind++;
|
||||
}
|
||||
optarg = NULL;
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
#endif /* HAVE_GETOPT */
|
@ -243,7 +243,6 @@ static int pageshift; /* log base 2 of the pagesize */
|
||||
/* useful externals */
|
||||
long percentages(int cnt, int *out, long *new, long *old, long *diffs);
|
||||
|
||||
#ifdef ORDER
|
||||
/*
|
||||
* Sorting orders. The first element is the default.
|
||||
*/
|
||||
@ -252,7 +251,6 @@ char *ordernames[] = {
|
||||
"total", "read", "write", "fault", "vcsw", "ivcsw",
|
||||
"jid", "swap", "pid", NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Per-cpu time states */
|
||||
static int maxcpu;
|
||||
@ -400,9 +398,7 @@ machine_init(struct statics *statics, char do_unames)
|
||||
else
|
||||
statics->carc_names = NULL;
|
||||
statics->swap_names = swapnames;
|
||||
#ifdef ORDER
|
||||
statics->order_names = ordernames;
|
||||
#endif
|
||||
|
||||
/* Allocate state for per-CPU stats. */
|
||||
cpumask = 0;
|
||||
@ -491,7 +487,6 @@ extern struct timeval timeout;
|
||||
void
|
||||
get_system_info(struct system_info *si)
|
||||
{
|
||||
long total;
|
||||
struct loadavg sysload;
|
||||
int mib[2];
|
||||
struct timeval boottime;
|
||||
@ -1382,11 +1377,7 @@ static int sorted_state[] = {
|
||||
/* compare_cpu - the comparison function for sorting by cpu percentage */
|
||||
|
||||
int
|
||||
#ifdef ORDER
|
||||
compare_cpu(void *arg1, void *arg2)
|
||||
#else
|
||||
proc_compare(void *arg1, void *arg2)
|
||||
#endif
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1401,7 +1392,6 @@ proc_compare(void *arg1, void *arg2)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef ORDER
|
||||
/* "cpu" compare routines */
|
||||
int compare_size(), compare_res(), compare_time(), compare_prio(),
|
||||
compare_threads();
|
||||
@ -1556,16 +1546,11 @@ compare_swap(const void *arg1, const void *arg2)
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif /* ORDER */
|
||||
|
||||
/* assorted comparison functions for sorting by i/o */
|
||||
|
||||
int
|
||||
#ifdef ORDER
|
||||
compare_iototal(void *arg1, void *arg2)
|
||||
#else
|
||||
io_compare(void *arg1, void *arg2)
|
||||
#endif
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1573,7 +1558,6 @@ io_compare(void *arg1, void *arg2)
|
||||
return (get_io_total(p2) - get_io_total(p1));
|
||||
}
|
||||
|
||||
#ifdef ORDER
|
||||
int
|
||||
compare_ioread(void *arg1, void *arg2)
|
||||
{
|
||||
@ -1638,7 +1622,6 @@ compare_ivcsw(void *arg1, void *arg2)
|
||||
|
||||
return (flp2 - flp1);
|
||||
}
|
||||
#endif /* ORDER */
|
||||
|
||||
/*
|
||||
* proc_owner(pid) - returns the uid that owns process "pid", or -1 if
|
||||
|
@ -23,9 +23,7 @@ struct statics
|
||||
char **arc_names;
|
||||
char **carc_names;
|
||||
char **swap_names;
|
||||
#ifdef ORDER
|
||||
char **order_names;
|
||||
#endif
|
||||
int ncpus;
|
||||
};
|
||||
|
||||
|
@ -105,12 +105,7 @@ char *ctime();
|
||||
char *kill_procs();
|
||||
char *renice_procs();
|
||||
|
||||
#ifdef ORDER
|
||||
extern int (*compares[])();
|
||||
#else
|
||||
extern int proc_compare();
|
||||
extern int io_compare();
|
||||
#endif
|
||||
time_t time();
|
||||
|
||||
caddr_t get_process_info(struct system_info *si, struct process_select *sel,
|
||||
@ -281,10 +276,8 @@ char *argv[];
|
||||
char *iptr;
|
||||
char no_command = 1;
|
||||
struct timeval timeout;
|
||||
#ifdef ORDER
|
||||
char *order_name = NULL;
|
||||
int order_index = 0;
|
||||
#endif
|
||||
#ifndef FD_SET
|
||||
/* FD_SET and friends are not present: fake it */
|
||||
typedef int fd_set;
|
||||
@ -293,11 +286,7 @@ char *argv[];
|
||||
#endif
|
||||
fd_set readfds;
|
||||
|
||||
#ifdef ORDER
|
||||
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJwo";
|
||||
#else
|
||||
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJw";
|
||||
#endif
|
||||
/* these defines enumerate the "strchr"s of the commands in command_chars */
|
||||
#define CMD_redraw 0
|
||||
#define CMD_update 1
|
||||
@ -326,9 +315,7 @@ char *argv[];
|
||||
#define CMD_pcputog 23
|
||||
#define CMD_jail 24
|
||||
#define CMD_swaptog 25
|
||||
#ifdef ORDER
|
||||
#define CMD_order 26
|
||||
#endif
|
||||
|
||||
/* set the buffer for stdout */
|
||||
#ifdef DEBUG
|
||||
@ -487,14 +474,7 @@ char *argv[];
|
||||
break;
|
||||
|
||||
case 'o': /* select sort order */
|
||||
#ifdef ORDER
|
||||
order_name = optarg;
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"%s: this platform does not support arbitrary ordering. Sorry.\n",
|
||||
myname);
|
||||
warnings++;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 't':
|
||||
@ -582,7 +562,6 @@ char *argv[];
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef ORDER
|
||||
/* determine sorting order index, if necessary */
|
||||
if (order_name != NULL)
|
||||
{
|
||||
@ -602,7 +581,6 @@ char *argv[];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef no_initialization_needed
|
||||
/* initialize the hashing stuff */
|
||||
@ -715,14 +693,7 @@ char *argv[];
|
||||
/* get the current stats */
|
||||
get_system_info(&system_info);
|
||||
|
||||
#ifdef ORDER
|
||||
compare = compares[order_index];
|
||||
#else
|
||||
if (displaymode == DISP_CPU)
|
||||
compare = proc_compare;
|
||||
else
|
||||
compare = io_compare;
|
||||
#endif
|
||||
|
||||
/* get the current set of processes */
|
||||
processes =
|
||||
@ -1144,7 +1115,6 @@ char *argv[];
|
||||
case CMD_showargs:
|
||||
fmt_flags ^= FMT_SHOWARGS;
|
||||
break;
|
||||
#ifdef ORDER
|
||||
case CMD_order:
|
||||
new_message(MT_standout,
|
||||
"Order to sort: ");
|
||||
@ -1167,7 +1137,6 @@ char *argv[];
|
||||
clear_message();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case CMD_jidtog:
|
||||
ps.jail = !ps.jail;
|
||||
new_message(MT_standout | MT_delayed,
|
||||
|
@ -337,32 +337,17 @@ long *diffs;
|
||||
|
||||
/* externs referenced by errmsg */
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
#ifndef SYS_ERRLIST_DECLARED
|
||||
#define SYS_ERRLIST_DECLARED
|
||||
extern char *sys_errlist[];
|
||||
#endif
|
||||
|
||||
extern int sys_nerr;
|
||||
#endif
|
||||
|
||||
char *errmsg(errnum)
|
||||
|
||||
int errnum;
|
||||
|
||||
{
|
||||
#ifdef HAVE_STRERROR
|
||||
char *msg = strerror(errnum);
|
||||
if (msg != NULL)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
#else
|
||||
if (errnum > 0 && errnum < sys_nerr)
|
||||
{
|
||||
return((char *)sys_errlist[errnum]);
|
||||
}
|
||||
#endif
|
||||
return("No error");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user