summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-02-25 18:21:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-02-25 18:21:25 +0000
commit93ebb63974b730657d6588a98524bd56827402de (patch)
tree55cbfcac59e35a0de6233b070515d828e4f1d37a
parent3486ed2c7b04753bdea156a76ee37f0ee29ce752 (diff)
use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna
-rw-r--r--usr.bin/systat/cmdtab.c8
-rw-r--r--usr.bin/systat/if.c5
-rw-r--r--usr.bin/systat/iostat.c6
-rw-r--r--usr.bin/systat/main.c73
-rw-r--r--usr.bin/systat/mbufs.c6
-rw-r--r--usr.bin/systat/netstat.c6
-rw-r--r--usr.bin/systat/pigs.c6
-rw-r--r--usr.bin/systat/sensors.c2
-rw-r--r--usr.bin/systat/swap.c6
-rw-r--r--usr.bin/systat/vmstat.c59
10 files changed, 77 insertions, 100 deletions
diff --git a/usr.bin/systat/cmdtab.c b/usr.bin/systat/cmdtab.c
index 29fc3db1170..46630e6ba72 100644
--- a/usr.bin/systat/cmdtab.c
+++ b/usr.bin/systat/cmdtab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdtab.c,v 1.8 2007/02/23 22:02:58 deanna Exp $ */
+/* $OpenBSD: cmdtab.c,v 1.9 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: cmdtab.c,v 1.2 1995/01/20 08:51:51 jtc Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.8 2007/02/23 22:02:58 deanna Exp $";
+static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.9 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -58,7 +58,7 @@ struct cmdtab cmdtab[] = {
CF_LOADAV },
{ "vmstat", showkre, fetchkre, labelkre,
initkre, openkre, closekre, cmdkre,
- 0 },
+ CF_LOADAV },
{ "netstat", shownetstat, fetchnetstat, labelnetstat,
initnetstat, opennetstat, closenetstat, cmdnetstat,
CF_LOADAV },
@@ -66,7 +66,7 @@ struct cmdtab cmdtab[] = {
initifstat, openifstat, closeifstat, cmdifstat,
CF_LOADAV },
{ "sensors", showsensors, fetchsensors, labelsensors,
- initsensors, opensensors, closesensors, 0,
+ initsensors, opensensors, closesensors, 0,
CF_LOADAV },
{ 0 }
};
diff --git a/usr.bin/systat/if.c b/usr.bin/systat/if.c
index 886a959e32e..75bedea161f 100644
--- a/usr.bin/systat/if.c
+++ b/usr.bin/systat/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.8 2006/11/28 19:21:15 reyk Exp $ */
+/* $OpenBSD: if.c,v 1.9 2007/02/25 18:21:24 deraadt Exp $ */
/*
* Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
*
@@ -58,7 +58,7 @@ WINDOW *
openifstat(void)
{
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-1, 0, 1, 0));
}
void
@@ -212,6 +212,7 @@ showlinkstate(int state)
case LINK_STATE_DOWN:
return (":D");
case LINK_STATE_UNKNOWN:
+ default:
return ("");
}
}
diff --git a/usr.bin/systat/iostat.c b/usr.bin/systat/iostat.c
index c31efc3c04f..8562c34d4c7 100644
--- a/usr.bin/systat/iostat.c
+++ b/usr.bin/systat/iostat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iostat.c,v 1.26 2006/06/29 21:17:27 dlg Exp $ */
+/* $OpenBSD: iostat.c,v 1.27 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: iostat.c,v 1.5 1996/05/10 23:16:35 thorpej Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: iostat.c,v 1.26 2006/06/29 21:17:27 dlg Exp $";
+static char rcsid[] = "$OpenBSD: iostat.c,v 1.27 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -64,7 +64,7 @@ static void numlabels(void);
WINDOW *
openiostat(void)
{
- return (subwin(stdscr, LINES-1-5, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-1, 0, 1, 0));
}
void
diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c
index 15eb1cb00c8..38ea76b7ec7 100644
--- a/usr.bin/systat/main.c
+++ b/usr.bin/systat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.34 2006/05/09 17:09:22 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.35 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */
/*-
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: main.c,v 1.34 2006/05/09 17:09:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.35 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -53,6 +53,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.34 2006/05/09 17:09:22 deraadt Exp $
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <utmp.h>
#include <stdlib.h>
#include <limits.h>
#include <stdarg.h>
@@ -69,7 +70,7 @@ double avenrun[3];
u_int naptime = 5;
int verbose = 1; /* to report kvm read errs */
int nflag = 0;
-int hz, stathz;
+int ut, hz, stathz;
char hostname[MAXHOSTNAMELEN];
WINDOW *wnd;
int CMDLINE;
@@ -81,10 +82,16 @@ static void usage(void);
int
main(int argc, char *argv[])
{
- int ch;
char errbuf[_POSIX2_LINE_MAX];
const char *errstr;
gid_t gid;
+ int ch;
+
+ ut = open(_PATH_UTMP, O_RDONLY);
+ if (ut < 0) {
+ error("No utmp");
+ exit(1);
+ }
kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
if (kd == NULL) {
@@ -157,7 +164,7 @@ main(int argc, char *argv[])
warnx("couldn't initialize display");
die();
}
- wload = newwin(1, 0, 3, 20);
+ wload = newwin(1, 0, 1, 20);
if (wload == NULL) {
warnx("couldn't set up load average window");
die();
@@ -207,11 +214,8 @@ usage(void)
void
labels(void)
{
- if (curcmd->c_flags & CF_LOADAV) {
- mvaddstr(2, 20,
- "/0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /10");
- mvaddstr(3, 5, "Load Average");
- }
+ if (curcmd->c_flags & CF_LOADAV)
+ mvprintw(0, 2 + 4, "users Load");
(*curcmd->c_label)();
#ifdef notdef
mvprintw(21, 25, "CPU usage on %s", hostname);
@@ -229,30 +233,22 @@ sigdisplay(int signo)
void
display(void)
{
- int i, j;
- chtype c;
-
/* Get the load average over the last minute. */
(void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
(*curcmd->c_fetch)();
if (curcmd->c_flags & CF_LOADAV) {
- j = 5.0*avenrun[0] + 0.5;
- dellave -= avenrun[0];
- if (dellave >= 0.0)
- c = '<';
- else {
- c = '>';
- dellave = -dellave;
- }
- if (dellave < 0.05)
- c = '|';
- dellave = avenrun[0];
- wmove(wload, 0, 0);
- wclrtoeol(wload);
- for (i = (j > 50) ? 50 : j; i > 0; i--)
- waddch(wload, c);
- if (j > 50)
- wprintw(wload, " %4.1f", avenrun[0]);
+ extern int ucount();
+ char tbuf[26];
+ time_t now;
+
+ time(&now);
+ strlcpy(tbuf, ctime(&now), sizeof tbuf);
+
+ putint(ucount(), 0, 2, 3);
+ putfloat(avenrun[0], 0, 2 + 17, 6, 2, 0);
+ putfloat(avenrun[1], 0, 2 + 23, 6, 2, 0);
+ putfloat(avenrun[2], 0, 2 + 29, 6, 2, 0);
+ mvaddstr(0, 2 + 53, tbuf);
}
(*curcmd->c_refresh)();
if (curcmd->c_flags & CF_LOADAV)
@@ -353,3 +349,20 @@ nlisterr(struct nlist namelist[])
endwin();
exit(1);
}
+
+/* calculate number of users on the system */
+int
+ucount(void)
+{
+ int nusers = 0;
+ struct utmp utmp;
+
+ if (ut < 0)
+ return (0);
+ lseek(ut, (off_t)0, SEEK_SET);
+ while (read(ut, &utmp, sizeof(utmp)))
+ if (utmp.ut_name[0] != '\0')
+ nusers++;
+
+ return (nusers);
+}
diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c
index d0d5f7c1989..357dc9126bf 100644
--- a/usr.bin/systat/mbufs.c
+++ b/usr.bin/systat/mbufs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbufs.c,v 1.16 2006/03/31 04:10:59 deraadt Exp $ */
+/* $OpenBSD: mbufs.c,v 1.17 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: mbufs.c,v 1.2 1995/01/20 08:52:02 jtc Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: mbufs.c,v 1.16 2006/03/31 04:10:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mbufs.c,v 1.17 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -73,7 +73,7 @@ char *mtnames[] = {
WINDOW *
openmbufs(void)
{
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-2, 0, 2, 0));
}
void
diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c
index b8bdaa6cf5a..b4a29e89f12 100644
--- a/usr.bin/systat/netstat.c
+++ b/usr.bin/systat/netstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.c,v 1.29 2006/03/31 04:10:59 deraadt Exp $ */
+/* $OpenBSD: netstat.c,v 1.30 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: netstat.c,v 1.3 1995/06/18 23:53:07 cgd Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: netstat.c,v 1.29 2006/03/31 04:10:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: netstat.c,v 1.30 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
/*
@@ -89,7 +89,7 @@ opennetstat(void)
{
sethostent(1);
setnetent(1);
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-2, 0, 2, 0));
}
struct netinfo {
diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c
index 21ea763ffb3..2f2640e8112 100644
--- a/usr.bin/systat/pigs.c
+++ b/usr.bin/systat/pigs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pigs.c,v 1.19 2006/11/29 12:34:22 miod Exp $ */
+/* $OpenBSD: pigs.c,v 1.20 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: pigs.c,v 1.3 1995/04/29 05:54:50 cgd Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93";
#endif
-static char rcsid[] = "$OpenBSD: pigs.c,v 1.19 2006/11/29 12:34:22 miod Exp $";
+static char rcsid[] = "$OpenBSD: pigs.c,v 1.20 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
/*
@@ -73,7 +73,7 @@ static double lccpu;
WINDOW *
openpigs(void)
{
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-2, 0, 2, 0));
}
void
diff --git a/usr.bin/systat/sensors.c b/usr.bin/systat/sensors.c
index f3e696c3b13..23a28d01fc8 100644
--- a/usr.bin/systat/sensors.c
+++ b/usr.bin/systat/sensors.c
@@ -37,7 +37,7 @@ void printline(void);
WINDOW *
opensensors(void)
{
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-1, 0, 1, 0));
}
void
diff --git a/usr.bin/systat/swap.c b/usr.bin/systat/swap.c
index 2752e09aee6..619a6d21721 100644
--- a/usr.bin/systat/swap.c
+++ b/usr.bin/systat/swap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: swap.c,v 1.18 2006/03/31 04:10:59 deraadt Exp $ */
+/* $OpenBSD: swap.c,v 1.19 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: swap.c,v 1.9 1998/12/26 07:05:08 marc Exp $ */
/*-
@@ -35,7 +35,7 @@
#if 0
static char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95";
#endif
-static char rcsid[] = "$OpenBSD: swap.c,v 1.18 2006/03/31 04:10:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: swap.c,v 1.19 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
#include <sys/cdefs.h>
@@ -63,7 +63,7 @@ static struct swapent *swap_devices;
WINDOW *
openswap(void)
{
- return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+ return (subwin(stdscr, LINES-1-2, 0, 2, 0));
}
void
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index e758f334e3c..bb33c675698 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmstat.c,v 1.61 2006/11/13 19:03:51 otto Exp $ */
+/* $OpenBSD: vmstat.c,v 1.62 2007/02/25 18:21:24 deraadt Exp $ */
/* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#endif
-static char rcsid[] = "$OpenBSD: vmstat.c,v 1.61 2006/11/13 19:03:51 otto Exp $";
+static char rcsid[] = "$OpenBSD: vmstat.c,v 1.62 2007/02/25 18:21:24 deraadt Exp $";
#endif /* not lint */
/*
@@ -59,7 +59,6 @@ static char rcsid[] = "$OpenBSD: vmstat.c,v 1.61 2006/11/13 19:03:51 otto Exp $"
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <utmp.h>
#include <unistd.h>
#include "systat.h"
@@ -90,13 +89,11 @@ static void copyinfo(struct Info *, struct Info *);
static float cputime(int);
static void dinfo(int, int);
static void getinfo(struct Info *);
-static void putint(int, int, int, int);
-static void putuint64(u_int64_t, int, int, int);
-static void putfloat(double, int, int, int, int, int);
-static int ucount(void);
+void putint(int, int, int, int);
+void putuint64(u_int64_t, int, int, int);
+void putfloat(double, int, int, int, int, int);
+int ucount(void);
-static int ut;
-static char buf[26];
static time_t t;
static double etime;
static float hertz;
@@ -105,30 +102,23 @@ static long *intrloc;
static char **intrname;
static int nextintsrow;
-struct utmp utmp;
-
WINDOW *
openkre(void)
{
-
- ut = open(_PATH_UTMP, O_RDONLY);
- if (ut < 0)
- error("No utmp");
- return (stdscr);
+ return (subwin(stdscr, LINES-1-1, 0, 1, 0));
}
void
closekre(WINDOW *w)
{
- (void) close(ut);
if (w == NULL)
return;
wclear(w);
wrefresh(w);
+ delwin(w);
}
-
/*
* These constants define where the major pieces are laid out
*/
@@ -213,10 +203,6 @@ initkre(void)
void
fetchkre(void)
{
- time_t now;
-
- time(&now);
- strlcpy(buf, ctime(&now), sizeof buf);
getinfo(&s);
}
@@ -225,8 +211,6 @@ labelkre(void)
{
int i, j, l;
- clear();
- mvprintw(STATROW, STATCOL + 4, "users Load");
mvprintw(MEMROW, MEMCOL, " memory totals (in KB)");
mvprintw(MEMROW + 1, MEMCOL, " real virtual free");
mvprintw(MEMROW + 2, MEMCOL, "Active");
@@ -387,11 +371,6 @@ showkre(void)
addch(cpuchar[c]);
}
- putint(ucount(), STATROW, STATCOL, 3);
- putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
- putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
- putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
- mvaddstr(STATROW, STATCOL + 53, buf);
#define pgtokb(pg) ((pg) * (s.uvmexp.pagesize / 1024))
putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 7, 8);
@@ -499,22 +478,6 @@ cmdkre(char *cmd, char *args)
return (dkcmd(cmd, args));
}
-/* calculate number of users on the system */
-static int
-ucount(void)
-{
- int nusers = 0;
-
- if (ut < 0)
- return (0);
- while (read(ut, &utmp, sizeof(utmp)))
- if (utmp.ut_name[0] != '\0')
- nusers++;
-
- lseek(ut, 0, SEEK_SET);
- return (nusers);
-}
-
static float
cputime(int indx)
{
@@ -529,7 +492,7 @@ cputime(int indx)
return (s.time[indx] * 100.0 / t);
}
-static void
+void
putint(int n, int l, int c, int w)
{
char b[128];
@@ -549,7 +512,7 @@ putint(int n, int l, int c, int w)
addstr(b);
}
-static void
+void
putuint64(u_int64_t n, int l, int c, int w)
{
char b[128];
@@ -569,7 +532,7 @@ putuint64(u_int64_t n, int l, int c, int w)
addstr(b);
}
-static void
+void
putfloat(double f, int l, int c, int w, int d, int nz)
{
char b[128];