top(1): clean much of WARNS=3 issues
There is still one glaring issue: new_message is not a protoype, but can't be trivially converted since it uses K&R style var-args.
This commit is contained in:
parent
4901ca088d
commit
666cf87393
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333951
@ -92,9 +92,9 @@ static int cpustates_column;
|
||||
|
||||
static enum { OFF, ON, ERASE } header_status = ON;
|
||||
|
||||
static int string_count();
|
||||
static void summary_format();
|
||||
static void line_update();
|
||||
static int string_count(char **);
|
||||
static void summary_format(char *, int *, char **);
|
||||
static void line_update(char *, char *, int, int);
|
||||
|
||||
int x_lastpid = 10;
|
||||
int y_lastpid = 0;
|
||||
@ -1041,11 +1041,9 @@ int hi;
|
||||
}
|
||||
|
||||
void
|
||||
display_header(t)
|
||||
|
||||
int t;
|
||||
|
||||
display_header(int t)
|
||||
{
|
||||
|
||||
if (t)
|
||||
{
|
||||
header_status = ON;
|
||||
@ -1058,17 +1056,12 @@ int t;
|
||||
|
||||
/*VARARGS2*/
|
||||
void
|
||||
new_message(type, msgfmt, a1, a2, a3)
|
||||
|
||||
int type;
|
||||
char *msgfmt;
|
||||
caddr_t a1, a2, a3;
|
||||
|
||||
new_message(int type, char *msgfmt, caddr_t a1, caddr_t a2, caddr_t a3)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* first, format the message */
|
||||
(void) snprintf(next_msg, sizeof(next_msg), msgfmt, a1, a2, a3);
|
||||
snprintf(next_msg, sizeof(next_msg), msgfmt, a1, a2, a3);
|
||||
|
||||
if (msglen > 0)
|
||||
{
|
||||
@ -1196,10 +1189,7 @@ int numeric;
|
||||
|
||||
/* internal support routines */
|
||||
|
||||
static int string_count(pp)
|
||||
|
||||
char **pp;
|
||||
|
||||
static int string_count(char **pp)
|
||||
{
|
||||
int cnt;
|
||||
|
||||
@ -1211,12 +1201,7 @@ char **pp;
|
||||
return(cnt);
|
||||
}
|
||||
|
||||
static void summary_format(str, numbers, names)
|
||||
|
||||
char *str;
|
||||
int *numbers;
|
||||
char **names;
|
||||
|
||||
static void summary_format(char *str, int *numbers, char **names)
|
||||
{
|
||||
char *p;
|
||||
int num;
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* $FreeBSD$ */
|
||||
/* constants needed for display.c */
|
||||
|
||||
/* "type" argument for new_message function */
|
||||
@ -27,7 +28,7 @@ void i_swap(int *stats);
|
||||
void i_timeofday(time_t *tod);
|
||||
void i_uptime(struct timeval *bt, time_t *tod);
|
||||
void new_message();
|
||||
int readline(char *buffer, int size, int numeric);
|
||||
int readline(char *buffer, int size, int numeric);
|
||||
char *trim_header(char *text);
|
||||
void u_arc(int *stats);
|
||||
void u_carc(int *stats);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <sys/user.h>
|
||||
#include <sys/vmmeter.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <kvm.h>
|
||||
#include <math.h>
|
||||
@ -460,6 +461,8 @@ format_header(char *uname_field)
|
||||
jidlength, ps.jail ? " JID" : "",
|
||||
namelength, namelength, uname_field);
|
||||
break;
|
||||
case DISP_MAX:
|
||||
assert("displaymode must not be set to DISP_MAX");
|
||||
}
|
||||
cmdlengthdelta = strlen(Header) - 7;
|
||||
return (Header);
|
||||
@ -624,7 +627,7 @@ get_system_info(struct system_info *si)
|
||||
* XXX: this could be done when the actual processes are fetched, we do
|
||||
* it here out of laziness.
|
||||
*/
|
||||
const struct kinfo_proc *
|
||||
static const struct kinfo_proc *
|
||||
get_old_proc(struct kinfo_proc *pp)
|
||||
{
|
||||
struct kinfo_proc **oldpp, *oldp;
|
||||
@ -667,7 +670,7 @@ get_old_proc(struct kinfo_proc *pp)
|
||||
* Return the total amount of IO done in blocks in/out and faults.
|
||||
* store the values individually in the pointers passed in.
|
||||
*/
|
||||
long
|
||||
static long
|
||||
get_io_stats(struct kinfo_proc *pp, long *inp, long *oup, long *flp,
|
||||
long *vcsw, long *ivcsw)
|
||||
{
|
||||
@ -741,7 +744,7 @@ proc_used_cpu(struct kinfo_proc *pp)
|
||||
/*
|
||||
* Return the total number of block in/out and faults by a process.
|
||||
*/
|
||||
long
|
||||
static long
|
||||
get_io_total(struct kinfo_proc *pp)
|
||||
{
|
||||
long dummy;
|
||||
@ -932,7 +935,8 @@ format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags)
|
||||
double pct;
|
||||
struct handle *hp;
|
||||
char status[16];
|
||||
int cpu, state;
|
||||
int cpu;
|
||||
size_t state;
|
||||
struct rusage ru, *rup;
|
||||
long p_tot, s_tot;
|
||||
char *proc_fmt, thr_buf[6];
|
||||
@ -995,7 +999,7 @@ format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags)
|
||||
state < sizeof(state_abbrev) / sizeof(*state_abbrev))
|
||||
sprintf(status, "%.6s", state_abbrev[state]);
|
||||
else
|
||||
sprintf(status, "?%5d", state);
|
||||
sprintf(status, "?%5lu", state);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1359,8 +1363,8 @@ static int sorted_state[] = {
|
||||
|
||||
/* compare_cpu - the comparison function for sorting by cpu percentage */
|
||||
|
||||
int
|
||||
compare_cpu(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_cpu(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1376,17 +1380,24 @@ compare_cpu(void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
/* "cpu" compare routines */
|
||||
int compare_size(), compare_res(), compare_time(), compare_prio(),
|
||||
compare_threads();
|
||||
static int compare_size(const void *arg1, const void *arg2);
|
||||
static int compare_res(const void *arg1, const void *arg2);
|
||||
static int compare_time(const void *arg1, const void *arg2);
|
||||
static int compare_prio(const void *arg1, const void *arg2);
|
||||
static int compare_threads(const void *arg1, const void *arg2);
|
||||
|
||||
/*
|
||||
* "io" compare routines. Context switches aren't i/o, but are displayed
|
||||
* on the "io" display.
|
||||
*/
|
||||
int compare_iototal(), compare_ioread(), compare_iowrite(), compare_iofault(),
|
||||
compare_vcsw(), compare_ivcsw();
|
||||
static int compare_iototal(const void *arg1, const void *arg2);
|
||||
static int compare_ioread(const void *arg1, const void *arg2);
|
||||
static int compare_iowrite(const void *arg1, const void *arg2);
|
||||
static int compare_iofault(const void *arg1, const void *arg2);
|
||||
static int compare_vcsw(const void *arg1, const void *arg2);
|
||||
static int compare_ivcsw(const void *arg1, const void *arg2);
|
||||
|
||||
int (*compares[])() = {
|
||||
int (*compares[])(const void *arg1, const void *arg2) = {
|
||||
compare_cpu,
|
||||
compare_size,
|
||||
compare_res,
|
||||
@ -1407,7 +1418,7 @@ int (*compares[])() = {
|
||||
/* compare_size - the comparison function for sorting by total memory usage */
|
||||
|
||||
int
|
||||
compare_size(void *arg1, void *arg2)
|
||||
compare_size(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1425,7 +1436,7 @@ compare_size(void *arg1, void *arg2)
|
||||
/* compare_res - the comparison function for sorting by resident set size */
|
||||
|
||||
int
|
||||
compare_res(void *arg1, void *arg2)
|
||||
compare_res(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1443,7 +1454,7 @@ compare_res(void *arg1, void *arg2)
|
||||
/* compare_time - the comparison function for sorting by total cpu time */
|
||||
|
||||
int
|
||||
compare_time(void *arg1, void *arg2)
|
||||
compare_time(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1461,7 +1472,7 @@ compare_time(void *arg1, void *arg2)
|
||||
/* compare_prio - the comparison function for sorting by priority */
|
||||
|
||||
int
|
||||
compare_prio(void *arg1, void *arg2)
|
||||
compare_prio(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1477,8 +1488,8 @@ compare_prio(void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
/* compare_threads - the comparison function for sorting by threads */
|
||||
int
|
||||
compare_threads(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_threads(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1533,7 +1544,7 @@ compare_swap(const void *arg1, const void *arg2)
|
||||
/* assorted comparison functions for sorting by i/o */
|
||||
|
||||
int
|
||||
compare_iototal(void *arg1, void *arg2)
|
||||
compare_iototal(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1541,8 +1552,8 @@ compare_iototal(void *arg1, void *arg2)
|
||||
return (get_io_total(p2) - get_io_total(p1));
|
||||
}
|
||||
|
||||
int
|
||||
compare_ioread(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_ioread(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1554,8 +1565,8 @@ compare_ioread(void *arg1, void *arg2)
|
||||
return (inp2 - inp1);
|
||||
}
|
||||
|
||||
int
|
||||
compare_iowrite(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_iowrite(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1567,8 +1578,8 @@ compare_iowrite(void *arg1, void *arg2)
|
||||
return (oup2 - oup1);
|
||||
}
|
||||
|
||||
int
|
||||
compare_iofault(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_iofault(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1580,8 +1591,8 @@ compare_iofault(void *arg1, void *arg2)
|
||||
return (flp2 - flp1);
|
||||
}
|
||||
|
||||
int
|
||||
compare_vcsw(void *arg1, void *arg2)
|
||||
static int
|
||||
compare_vcsw(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
@ -1594,7 +1605,7 @@ compare_vcsw(void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
int
|
||||
compare_ivcsw(void *arg1, void *arg2)
|
||||
compare_ivcsw(const void *arg1, const void *arg2)
|
||||
{
|
||||
struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
|
||||
struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
|
||||
|
@ -23,9 +23,10 @@
|
||||
#include "top.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
# define TERMIOS
|
||||
# include <termios.h>
|
||||
#define TERMIOS
|
||||
#include <termios.h>
|
||||
#include <curses.h>
|
||||
#include <termcap.h>
|
||||
#include "screen.h"
|
||||
@ -41,8 +42,6 @@ char ch_erase;
|
||||
char ch_kill;
|
||||
char smart_terminal;
|
||||
char PC;
|
||||
char *tgetstr();
|
||||
char *tgoto();
|
||||
char termcap_buf[1024];
|
||||
char string_buffer[1024];
|
||||
char home[15];
|
||||
@ -73,7 +72,6 @@ int interactive;
|
||||
char *bufptr;
|
||||
char *PCptr;
|
||||
char *term_name;
|
||||
char *getenv();
|
||||
int status;
|
||||
|
||||
/* set defaults in case we aren't smart */
|
||||
|
@ -3,16 +3,14 @@
|
||||
*
|
||||
* This file contains all the definitions necessary to use the hand-written
|
||||
* screen package in "screen.c"
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define TCputs(str) tputs(str, 1, putstdout)
|
||||
#define putcap(str) (void)((str) != NULL ? TCputs(str) : 0)
|
||||
#define Move_to(x, y) TCputs(tgoto(cursor_motion, x, y))
|
||||
|
||||
/* declare return values for termcap functions */
|
||||
char *tgetstr();
|
||||
char *tgoto();
|
||||
|
||||
extern char ch_erase; /* set to the user's erase character */
|
||||
extern char ch_kill; /* set to the user's kill character */
|
||||
extern char smart_terminal; /* set if the terminal has sufficient termcap
|
||||
|
@ -81,16 +81,16 @@ static int fmt_flags = 0;
|
||||
int pcpu_stats = No;
|
||||
|
||||
/* signal handling routines */
|
||||
sigret_t leave();
|
||||
sigret_t tstop();
|
||||
sigret_t top_winch(int);
|
||||
static sigret_t leave(int);
|
||||
static sigret_t tstop(int);
|
||||
static sigret_t top_winch(int);
|
||||
|
||||
volatile sig_atomic_t leaveflag;
|
||||
volatile sig_atomic_t tstopflag;
|
||||
volatile sig_atomic_t winchflag;
|
||||
|
||||
/* internal routines */
|
||||
void quit();
|
||||
void quit(int);
|
||||
|
||||
/* values which need to be accessed by signal handlers */
|
||||
static int max_topn; /* maximum displayable processes */
|
||||
@ -100,20 +100,18 @@ struct process_select ps;
|
||||
char *myname = "top";
|
||||
jmp_buf jmp_int;
|
||||
|
||||
/* routines that don't return int */
|
||||
char *username(int);
|
||||
|
||||
char *username();
|
||||
|
||||
extern int (*compares[])();
|
||||
time_t time();
|
||||
extern int (*compares[])(const void*, const void*);
|
||||
time_t time(time_t *tloc);
|
||||
|
||||
caddr_t get_process_info(struct system_info *si, struct process_select *sel,
|
||||
int (*compare)(const void *, const void *));
|
||||
|
||||
/* different routines for displaying the user's identification */
|
||||
/* (values assigned to get_userid) */
|
||||
char *username();
|
||||
char *itoa7();
|
||||
char *username(int);
|
||||
char *itoa7(int);
|
||||
|
||||
/* pointers to display routines */
|
||||
void (*d_loadave)(int mpid, double *avenrun) = i_loadave;
|
||||
@ -632,10 +630,10 @@ char *argv[];
|
||||
old_sigmask = sigblock(Smask(SIGINT) | Smask(SIGQUIT) | Smask(SIGTSTP));
|
||||
#endif
|
||||
init_screen();
|
||||
(void) signal(SIGINT, leave);
|
||||
(void) signal(SIGQUIT, leave);
|
||||
(void) signal(SIGTSTP, tstop);
|
||||
(void) signal(SIGWINCH, top_winch);
|
||||
signal(SIGINT, leave);
|
||||
signal(SIGQUIT, leave);
|
||||
signal(SIGTSTP, tstop);
|
||||
signal(SIGWINCH, top_winch);
|
||||
#ifdef SIGRELSE
|
||||
sigrelse(SIGINT);
|
||||
sigrelse(SIGQUIT);
|
||||
@ -1228,30 +1226,30 @@ reset_display()
|
||||
* signal handlers
|
||||
*/
|
||||
|
||||
sigret_t leave() /* exit under normal conditions -- INT handler */
|
||||
static sigret_t
|
||||
leave(int i __unused) /* exit under normal conditions -- INT handler */
|
||||
{
|
||||
|
||||
leaveflag = 1;
|
||||
}
|
||||
|
||||
sigret_t tstop(int i __unused) /* SIGTSTP handler */
|
||||
static sigret_t
|
||||
tstop(int i __unused) /* SIGTSTP handler */
|
||||
{
|
||||
|
||||
tstopflag = 1;
|
||||
}
|
||||
|
||||
sigret_t top_winch(int i __unused) /* SIGWINCH handler */
|
||||
static sigret_t
|
||||
top_winch(int i __unused) /* SIGWINCH handler */
|
||||
{
|
||||
|
||||
winchflag = 1;
|
||||
}
|
||||
|
||||
void quit(status) /* exit under duress */
|
||||
|
||||
int status;
|
||||
|
||||
void
|
||||
quit(int status) /* exit under duress */
|
||||
{
|
||||
end_screen();
|
||||
exit(status);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user