- use snprintf
- don't overwrite the keyboard buffer (and make this sized on
  the window size).
This commit is contained in:
mrg 1998-07-12 05:59:00 +00:00
parent 55a09b0837
commit 47abaab886
10 changed files with 88 additions and 60 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: disks.c,v 1.6 1997/10/19 23:36:23 lukem Exp $ */
/* $NetBSD: disks.c,v 1.7 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: disks.c,v 1.6 1997/10/19 23:36:23 lukem Exp $");
__RCSID("$NetBSD: disks.c,v 1.7 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -51,12 +51,13 @@ __RCSID("$NetBSD: disks.c,v 1.6 1997/10/19 23:36:23 lukem Exp $");
#include "systat.h"
#include "extern.h"
static void dkselect(char *args, int truefalse, int selections[]);
static void dkselect __P((char *args, int truefalse, int selections[]));
int
dkcmd(cmd, args)
char *cmd, *args;
{
if (prefix(cmd, "display") || prefix(cmd, "add")) {
dkselect(args, 1, dk_select);
return (1);
@ -68,7 +69,8 @@ dkcmd(cmd, args)
if (prefix(cmd, "drives")) {
int i;
move(CMDLINE, 0); clrtoeol();
move(CMDLINE, 0);
clrtoeol();
for (i = 0; i < dk_ndrive; i++)
printw("%s ", dr_name[i]);
return (1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.3 1997/07/21 07:05:01 mrg Exp $ */
/* $NetBSD: fetch.c,v 1.4 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)fetch.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: fetch.c,v 1.3 1997/07/21 07:05:01 mrg Exp $");
__RCSID("$NetBSD: fetch.c,v 1.4 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -54,7 +54,6 @@ kvm_ckread(a, b, l)
if (verbose)
error("error reading kmem at %x\n", a);
return (0);
}
else
} else
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: iostat.c,v 1.9 1997/10/19 23:36:24 lukem Exp $ */
/* $NetBSD: iostat.c,v 1.10 1998/07/12 05:59:00 mrg Exp $ */
/*
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: iostat.c,v 1.9 1997/10/19 23:36:24 lukem Exp $");
__RCSID("$NetBSD: iostat.c,v 1.10 1998/07/12 05:59:00 mrg Exp $");
#endif not lint
#include <sys/param.h>
@ -303,7 +303,7 @@ histogram(val, colwidth, scale)
k = MIN(v, colwidth);
if (v > colwidth) {
sprintf(buf, "%4.1f", val);
snprintf(buf, sizeof buf, "%4.1f", val);
k -= strlen(buf);
while (k--)
waddch(wnd, 'X');

View File

@ -1,4 +1,4 @@
/* $NetBSD: keyboard.c,v 1.4 1997/07/21 07:05:02 mrg Exp $ */
/* $NetBSD: keyboard.c,v 1.5 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,12 +38,16 @@
#if 0
static char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: keyboard.c,v 1.4 1997/07/21 07:05:02 mrg Exp $");
__RCSID("$NetBSD: keyboard.c,v 1.5 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
#include <curses.h>
#include <signal.h>
#include <termios.h>
#include <stdlib.h>
#include "systat.h"
#include "extern.h"
@ -51,12 +55,20 @@ __RCSID("$NetBSD: keyboard.c,v 1.4 1997/07/21 07:05:02 mrg Exp $");
int
keyboard()
{
char ch, line[80];
char ch, *line;
int linesz;
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
linesz = COLS - 2; /* XXX does not get updated on SIGWINCH */
line = malloc(linesz);
if (line == NULL) {
error("malloc");
exit(1);
}
for (;;) {
col = 0;
move(CMDLINE, 0);
@ -103,19 +115,22 @@ keyboard()
goto doerase;
}
if (ch == killchar() && col > 0) {
col = 0;
if (line[0] == ':')
col++;
col = 1;
else
col = 0;
doerase:
move(CMDLINE, col);
clrtoeol();
continue;
}
if (isprint(ch) || ch == ' ') {
if (col < linesz) {
line[col] = ch;
mvaddch(CMDLINE, col, ch);
col++;
}
}
} while (col == 0 || (ch != '\r' && ch != '\n'));
line[col] = '\0';
sigprocmask(SIG_BLOCK, &set, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.13 1998/07/06 06:55:24 mrg Exp $ */
/* $NetBSD: main.c,v 1.14 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: main.c,v 1.13 1998/07/06 06:55:24 mrg Exp $");
__RCSID("$NetBSD: main.c,v 1.14 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -235,7 +235,7 @@ display(signo)
int i, j;
/* Get the load average over the last minute. */
(void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
(void)getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
(*curcmd->c_fetch)();
if (curcmd->c_flags & CF_LOADAV) {
j = 5.0*avenrun[0] + 0.5;
@ -282,7 +282,7 @@ void
load()
{
(void) getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
(void)getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
mvprintw(CMDLINE, 0, "%4.1f %4.1f %4.1f",
avenrun[0], avenrun[1], avenrun[2]);
clrtoeol();

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbufs.c,v 1.5 1997/10/19 23:36:27 lukem Exp $ */
/* $NetBSD: mbufs.c,v 1.6 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: mbufs.c,v 1.5 1997/10/19 23:36:27 lukem Exp $");
__RCSID("$NetBSD: mbufs.c,v 1.6 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -76,6 +76,7 @@ char *mtnames[] = {
WINDOW *
openmbufs()
{
return (subwin(stdscr, LINES-5-1, 0, 5, 0));
}
@ -83,6 +84,7 @@ void
closembufs(w)
WINDOW *w;
{
if (w == NULL)
return;
wclear(w);
@ -93,6 +95,7 @@ closembufs(w)
void
labelmbufs()
{
wmove(wnd, 0, 0); wclrtoeol(wnd);
mvwaddstr(wnd, 0, 10,
"/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50 /55 /60");
@ -121,7 +124,7 @@ showmbufs()
mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
wmove(wnd, 1 + j, 10);
if (max > 60) {
sprintf(buf, " %d", max);
snprintf(buf, sizeof buf, " %d", max);
max = 60;
while (max--)
waddch(wnd, 'X');
@ -145,6 +148,7 @@ static struct nlist namelist[] = {
int
initmbufs()
{
if (namelist[X_MBSTAT].n_type == 0) {
if (kvm_nlist(kd, namelist)) {
nlisterr(namelist);
@ -163,6 +167,7 @@ initmbufs()
void
fetchmbufs()
{
if (namelist[X_MBSTAT].n_type == 0)
return;
NREAD(X_MBSTAT, mb, sizeof (*mb));

View File

@ -1,4 +1,4 @@
/* $NetBSD: netcmds.c,v 1.7 1998/04/02 11:18:25 kleink Exp $ */
/* $NetBSD: netcmds.c,v 1.8 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: netcmds.c,v 1.7 1998/04/02 11:18:25 kleink Exp $");
__RCSID("$NetBSD: netcmds.c,v 1.8 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
/*
@ -180,10 +180,10 @@ static void
showprotos()
{
if ((protos&TCP) == 0)
if ((protos & TCP) == 0)
addch('!');
addstr("tcp ");
if ((protos&UDP) == 0)
if ((protos & UDP) == 0)
addch('!');
addstr("udp ");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netstat.c,v 1.8 1997/10/19 23:36:29 lukem Exp $ */
/* $NetBSD: netstat.c,v 1.9 1998/07/12 05:59:00 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: netstat.c,v 1.8 1997/10/19 23:36:29 lukem Exp $");
__RCSID("$NetBSD: netstat.c,v 1.9 1998/07/12 05:59:00 mrg Exp $");
#endif /* not lint */
/*
@ -86,14 +86,6 @@ static void inetprint __P((struct in_addr *, int, char *));
#define streq(a,b) (strcmp(a,b)==0)
WINDOW *
opennetstat()
{
sethostent(1);
setnetent(1);
return (subwin(stdscr, LINES-5-1, 0, 5, 0));
}
struct netinfo {
struct netinfo *ni_forw, *ni_prev;
short ni_line; /* line on screen */
@ -122,6 +114,15 @@ static void enter __P((struct inpcb *, struct socket *, int, char *));
static void inetprint __P((struct in_addr *, int, char *));
static char *inetname __P((struct in_addr));
WINDOW *
opennetstat()
{
sethostent(1);
setnetent(1);
return (subwin(stdscr, LINES-5-1, 0, 5, 0));
}
void
closenetstat(w)
WINDOW *w;
@ -290,10 +291,10 @@ enter(inp, so, state, proto)
#define SNDCC RCVCC+7
#define STATE SNDCC+7
void
labelnetstat()
{
if (namelist[X_TCBTABLE].n_type == 0)
return;
wmove(wnd, 0, 0); wclrtobot(wnd);
@ -390,14 +391,16 @@ inetprint(in, port, proto)
struct servent *sp = 0;
char line[80], *cp;
sprintf(line, "%.*s.", 16, inetname(*in));
(void)snprintf(line, sizeof line, "%.*s.", 16, inetname(*in));
cp = strchr(line, '\0');
if (!nflag && port)
sp = getservbyport(port, proto);
if (sp || port == 0)
sprintf(cp, "%.8s", sp ? sp->s_name : "*");
(void)snprintf(cp, line + sizeof line - cp, "%.8s",
sp ? sp->s_name : "*");
else
sprintf(cp, "%d", ntohs((u_short)port));
(void)snprintf(cp, line + sizeof line - cp, "%d",
ntohs((u_short)port));
/* pad to full column to clear any garbage */
cp = strchr(line, '\0');
while (cp - line < 22)
@ -436,15 +439,18 @@ inetname(in)
}
}
if (in.s_addr == INADDR_ANY)
strcpy(line, "*");
strncpy(line, "*", sizeof(line) - 1);
else if (cp)
strcpy(line, cp);
strncpy(line, cp, sizeof(line) - 1);
else {
in.s_addr = ntohl(in.s_addr);
#define C(x) ((x) & 0xff)
sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24),
C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr));
(void)snprintf(line, sizeof line, "%u.%u.%u.%u",
C(in.s_addr >> 24), C(in.s_addr >> 16),
C(in.s_addr >> 8), C(in.s_addr));
#undef C
}
line[sizeof(line) - 1] = '\0';
return (line);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pigs.c,v 1.9 1998/05/17 18:18:18 mycroft Exp $ */
/* $NetBSD: pigs.c,v 1.10 1998/07/12 05:59:01 mrg Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93";
#endif
__RCSID("$NetBSD: pigs.c,v 1.9 1998/05/17 18:18:18 mycroft Exp $");
__RCSID("$NetBSD: pigs.c,v 1.10 1998/07/12 05:59:01 mrg Exp $");
#endif /* not lint */
/*
@ -77,6 +77,7 @@ static double lccpu;
WINDOW *
openpigs()
{
return (subwin(stdscr, LINES-5-1, 0, 5, 0));
}
@ -84,6 +85,7 @@ void
closepigs(w)
WINDOW *w;
{
if (w == NULL)
return;
wclear(w);
@ -132,7 +134,7 @@ showpigs()
wmove(wnd, y, 0);
wclrtoeol(wnd);
mvwaddstr(wnd, y, 0, uname);
sprintf(pidname, "%10.10s", pname);
(void)snprintf(pidname, sizeof pidname, "%10.10s", pname);
mvwaddstr(wnd, y, 9, pidname);
wmove(wnd, y, 20);
for (j = pt[k].pt_pctcpu*factor + 0.5; j > 0; j--)

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmstat.c,v 1.13 1998/02/09 15:29:52 mrg Exp $ */
/* $NetBSD: vmstat.c,v 1.14 1998/07/12 05:59:01 mrg Exp $ */
/*-
* Copyright (c) 1983, 1989, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#endif
__RCSID("$NetBSD: vmstat.c,v 1.13 1998/02/09 15:29:52 mrg Exp $");
__RCSID("$NetBSD: vmstat.c,v 1.14 1998/07/12 05:59:01 mrg Exp $");
#endif /* not lint */
/*
@ -397,7 +397,6 @@ showkre()
int i, l, c;
static int failcnt = 0;
if (state == TIME)
dkswap();
etime = 0;
@ -661,7 +660,7 @@ putint(n, l, c, w)
addch(' ');
return;
}
sprintf(b, "%*d", w, n);
(void)snprintf(b, sizeof b, "%*d", w, n);
if (strlen(b) > w) {
while (w-- > 0)
addch('*');
@ -683,7 +682,7 @@ putfloat(f, l, c, w, d, nz)
addch(' ');
return;
}
sprintf(b, "%*.*f", w, d, f);
(void)snprintf(b, sizeof b, "%*.*f", w, d, f);
if (strlen(b) > w) {
while (--w >= 0)
addch('*');