Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Nov 2012 00:13:31 +0000 (UTC)
From:      "Alexander V. Chernikov" <melifaro@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r243684 - stable/8/usr.bin/systat
Message-ID:  <201211300013.qAU0DWa1081430@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: melifaro
Date: Fri Nov 30 00:13:31 2012
New Revision: 243684
URL: http://svnweb.freebsd.org/changeset/base/243684

Log:
  Merge r226396, r240605
  
  Make systat(1) accept fractional number of seconds.
  Make old alarm(3)-based code use select(2).
  
  Ability to specify small intervals can be very handy while
  debugging traffic microbursts.
  
  Note that locale-aware strtod(3) is used to parse delay which
  is slightly different from ping.
  
  Fix whitespace inconsistencies in systat(1).
  
  Approved by:	ed (r226396)

Modified:
  stable/8/usr.bin/systat/cmds.c
  stable/8/usr.bin/systat/cmdtab.c
  stable/8/usr.bin/systat/devs.c
  stable/8/usr.bin/systat/extern.h
  stable/8/usr.bin/systat/fetch.c
  stable/8/usr.bin/systat/icmp.c
  stable/8/usr.bin/systat/icmp6.c
  stable/8/usr.bin/systat/ifcmds.c
  stable/8/usr.bin/systat/ifstat.c
  stable/8/usr.bin/systat/ip.c
  stable/8/usr.bin/systat/ip6.c
  stable/8/usr.bin/systat/keyboard.c
  stable/8/usr.bin/systat/main.c
  stable/8/usr.bin/systat/mode.c
  stable/8/usr.bin/systat/mode.h
  stable/8/usr.bin/systat/netstat.c
  stable/8/usr.bin/systat/systat.1
  stable/8/usr.bin/systat/systat.h
  stable/8/usr.bin/systat/tcp.c
  stable/8/usr.bin/systat/vmstat.c
Directory Properties:
  stable/8/usr.bin/   (props changed)
  stable/8/usr.bin/systat/   (props changed)

Modified: stable/8/usr.bin/systat/cmds.c
==============================================================================
--- stable/8/usr.bin/systat/cmds.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/cmds.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$");
 static const char sccsid[] = "@(#)cmds.c	8.2 (Berkeley) 4/29/95";
 #endif
 
+#include <sys/param.h>
+
 #include <ctype.h>
 #include <signal.h>
 #include <stdlib.h>
@@ -51,32 +53,31 @@ static const char sccsid[] = "@(#)cmds.c
 void
 command(const char *cmd)
 {
-        struct cmdtab *p;
-        char *cp, *tmpstr, *tmpstr1;
-	int interval, omask;
+	struct cmdtab *p;
+	char *cp, *tmpstr, *tmpstr1;
+	double t;
 
 	tmpstr = tmpstr1 = strdup(cmd);
-	omask = sigblock(sigmask(SIGALRM));
-        for (cp = tmpstr1; *cp && !isspace(*cp); cp++)
-                ;
-        if (*cp)
-                *cp++ = '\0';
+	for (cp = tmpstr1; *cp && !isspace(*cp); cp++)
+		;
+	if (*cp)
+		*cp++ = '\0';
 	if (*tmpstr1 == '\0')
 		return;
 	for (; *cp && isspace(*cp); cp++)
 		;
-        if (strcmp(tmpstr1, "quit") == 0 || strcmp(tmpstr1, "q") == 0)
-                die(0);
+	if (strcmp(tmpstr1, "quit") == 0 || strcmp(tmpstr1, "q") == 0)
+		die(0);
 	if (strcmp(tmpstr1, "load") == 0) {
 		load();
 		goto done;
 	}
-        if (strcmp(tmpstr1, "stop") == 0) {
-                alarm(0);
-                mvaddstr(CMDLINE, 0, "Refresh disabled.");
-                clrtoeol();
+	if (strcmp(tmpstr1, "stop") == 0) {
+		delay = 0;
+		mvaddstr(CMDLINE, 0, "Refresh disabled.");
+		clrtoeol();
 		goto done;
-        }
+	}
 	if (strcmp(tmpstr1, "help") == 0) {
 		int _col, _len;
 
@@ -92,31 +93,34 @@ command(const char *cmd)
 		clrtoeol();
 		goto done;
 	}
-	interval = atoi(tmpstr1);
-        if (interval <= 0 &&
-	    (strcmp(tmpstr1, "start") == 0 || strcmp(tmpstr1, "interval") == 0)) {
-		interval = *cp ? atoi(cp) : naptime;
-                if (interval <= 0) {
-			error("%d: bad interval.", interval);
-			goto done;
-                }
+	t = strtod(tmpstr1, NULL) * 1000000.0;
+	if (t > 0 && t < (double)UINT_MAX)
+		delay = (unsigned int)t;
+	if ((t <= 0 || t > (double)UINT_MAX) &&
+	    (strcmp(tmpstr1, "start") == 0 ||
+	    strcmp(tmpstr1, "interval") == 0)) {
+		if (*cp != '\0') {
+			t = strtod(cp, NULL) * 1000000.0;
+			if (t <= 0 || t >= (double)UINT_MAX) {
+				error("%d: bad interval.", (int)t);
+				goto done;
+			}
+		}
 	}
-	if (interval > 0) {
-                alarm(0);
-                naptime = interval;
-                display(0);
-                status();
+	if (t > 0) {
+		delay = (unsigned int)t;
+		display();
+		status();
 		goto done;
-        }
+	}
 	p = lookup(tmpstr1);
 	if (p == (struct cmdtab *)-1) {
 		error("%s: Ambiguous command.", tmpstr1);
 		goto done;
 	}
-        if (p) {
-                if (curcmd == p)
+	if (p) {
+		if (curcmd == p)
 			goto done;
-                alarm(0);
 		(*curcmd->c_close)(wnd);
 		curcmd->c_flags &= ~CF_INIT;
 		wnd = (*p->c_open)();
@@ -135,16 +139,15 @@ command(const char *cmd)
 			else
 				goto done;
 		}
-                curcmd = p;
+		curcmd = p;
 		labels();
-                display(0);
-                status();
+		display();
+		status();
 		goto done;
-        }
+	}
 	if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(tmpstr1, cp))
 		error("%s: Unknown command.", tmpstr1);
 done:
-	sigsetmask(omask);
 	free(tmpstr);
 }
 
@@ -180,18 +183,18 @@ void
 status(void)
 {
 
-        error("Showing %s, refresh every %d seconds.",
-          curcmd->c_name, naptime);
+	error("Showing %s, refresh every %d seconds.",
+	  curcmd->c_name, delay / 1000000);
 }
 
 int
 prefix(const char *s1, const char *s2)
 {
 
-        while (*s1 == *s2) {
-                if (*s1 == '\0')
-                        return (1);
-                s1++, s2++;
-        }
-        return (*s1 == '\0');
+	while (*s1 == *s2) {
+		if (*s1 == '\0')
+			return (1);
+		s1++, s2++;
+	}
+	return (*s1 == '\0');
 }

Modified: stable/8/usr.bin/systat/cmdtab.c
==============================================================================
--- stable/8/usr.bin/systat/cmdtab.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/cmdtab.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -44,22 +44,22 @@ static const char sccsid[] = "@(#)cmdtab
 #include "mode.h"
 
 struct	cmdtab cmdtab[] = {
-        { "pigs",	showpigs,	fetchpigs,	labelpigs,
+	{ "pigs",	showpigs,	fetchpigs,	labelpigs,
 	  initpigs,	openpigs,	closepigs,	0,
 	  0,		CF_LOADAV },
-        { "swap",	showswap,	fetchswap,	labelswap,
+	{ "swap",	showswap,	fetchswap,	labelswap,
 	  initswap,	openswap,	closeswap,	0,
 	  0,		CF_LOADAV },
-        { "mbufs",	showmbufs,	fetchmbufs,	labelmbufs,
+	{ "mbufs",	showmbufs,	fetchmbufs,	labelmbufs,
 	  initmbufs,	openmbufs,	closembufs,	0,
 	  0,		CF_LOADAV },
-        { "iostat",	showiostat,	fetchiostat,	labeliostat,
+	{ "iostat",	showiostat,	fetchiostat,	labeliostat,
 	  initiostat,	openiostat,	closeiostat,	cmdiostat,
 	  0,		CF_LOADAV },
-        { "vmstat",	showkre,	fetchkre,	labelkre,
+	{ "vmstat",	showkre,	fetchkre,	labelkre,
 	  initkre,	openkre,	closekre,	cmdkre,
 	  0,		0 },
-        { "netstat",	shownetstat,	fetchnetstat,	labelnetstat,
+	{ "netstat",	shownetstat,	fetchnetstat,	labelnetstat,
 	  initnetstat,	opennetstat,	closenetstat,	cmdnetstat,
 	  0,		CF_LOADAV },
 	{ "icmp",	showicmp,	fetchicmp,	labelicmp,
@@ -82,6 +82,6 @@ struct	cmdtab cmdtab[] = {
 	{ "ifstat",	showifstat,	fetchifstat,	labelifstat,
 	  initifstat,	openifstat,	closeifstat,	cmdifstat,
 	  0,		CF_LOADAV },
-        { NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0 }
+	{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0 }
 };
 struct  cmdtab *curcmd = &cmdtab[0];

Modified: stable/8/usr.bin/systat/devs.c
==============================================================================
--- stable/8/usr.bin/systat/devs.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/devs.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -109,7 +109,7 @@ dsinit(int maxshowdevs, struct statinfo 
 
 	/*
 	 * Make sure that the userland devstat version matches the kernel
-	 * devstat version.  If not, exit and print a message informing 
+	 * devstat version.  If not, exit and print a message informing
 	 * the user of his mistake.
 	 */
 	if (devstat_checkversion(NULL) < 0)
@@ -159,10 +159,10 @@ dscmd(const char *cmd, const char *args,
 	if (prefix(cmd, "refresh")) {
 		retval = devstat_selectdevs(&dev_select, &num_selected,
 		    &num_selections, &select_generation, generation,
-		    s1->dinfo->devices, num_devices, 
+		    s1->dinfo->devices, num_devices,
 		    (last_type ==DS_MATCHTYPE_PATTERN) ?  matches : NULL,
 		    (last_type ==DS_MATCHTYPE_PATTERN) ?  num_matches : 0,
-		    (last_type == DS_MATCHTYPE_SPEC) ?specified_devices : NULL, 
+		    (last_type == DS_MATCHTYPE_SPEC) ?specified_devices : NULL,
 		    (last_type == DS_MATCHTYPE_SPEC) ?num_devices_specified : 0,
 		    (last_type == DS_MATCHTYPE_NONE) ?  DS_SELECT_ADD :
 		    DS_SELECT_ADDONLY, maxshowdevs, 0);
@@ -224,7 +224,7 @@ dsmatchselect(const char *args, devstat_
 	}
 
 	for (i = 0; i < num_args; i++) {
-		if (devstat_buildmatch(tstr[i], &matches, &num_matches) != 0) {	
+		if (devstat_buildmatch(tstr[i], &matches, &num_matches) != 0) {
 			warnx("%s", devstat_errbuf);
 			return(0);
 		}
@@ -286,7 +286,7 @@ dsselect(const char *args, devstat_selec
 			asprintf(&buffer, "%s%d", dev_select[i].device_name,
 				dev_select[i].unit_number);
 			if (strcmp(buffer, tmpstr1) == 0) {
-				
+
 				num_devices_specified++;
 
 				specified_devices =(char **)realloc(

Modified: stable/8/usr.bin/systat/extern.h
==============================================================================
--- stable/8/usr.bin/systat/extern.h	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/extern.h	Fri Nov 30 00:13:31 2012	(r243684)
@@ -53,11 +53,12 @@ extern int	CMDLINE;
 extern int	dk_ndrive;
 extern int	hz, stathz;
 extern double	hertz;		/* sampling frequency for cp_time and dk_time */
-extern int	naptime, col;
+extern int	col;
 extern int	nhosts;
 extern int	nports;
 extern int	protos;
 extern int	verbose;
+extern unsigned int	delay;
 
 struct inpcb;
 
@@ -91,7 +92,7 @@ int	 cmdnetstat(const char *, const char
 struct	 cmdtab *lookup(const char *);
 void	 command(const char *);
 void	 die(int);
-void	 display(int);
+void	 display(void);
 int	 dkinit(void);
 int	 dkcmd(char *, char *);
 void	 error(const char *fmt, ...) __printflike(1, 2);

Modified: stable/8/usr.bin/systat/fetch.c
==============================================================================
--- stable/8/usr.bin/systat/fetch.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/fetch.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -66,17 +66,17 @@ void getsysctl(const char *name, void *p
 {
 	size_t nlen = len;
 	if (sysctlbyname(name, ptr, &nlen, NULL, 0) != 0) {
-		error("sysctl(%s...) failed: %s", name, 
+		error("sysctl(%s...) failed: %s", name,
 		    strerror(errno));
 	}
 	if (nlen != len) {
-		error("sysctl(%s...) expected %lu, got %lu", name, 
+		error("sysctl(%s...) expected %lu, got %lu", name,
 		    (unsigned long)len, (unsigned long)nlen);
     }
 }
 
 /*
- * Read sysctl data with variable size. Try some times (with increasing 
+ * Read sysctl data with variable size. Try some times (with increasing
  * buffers), fail if still too small.
  * This is needed sysctls with possibly raplidly increasing data sizes,
  * but imposes little overhead in the case of constant sizes.
@@ -88,8 +88,8 @@ void getsysctl(const char *name, void *p
 /* Some defines: Number of tries. */
 #define SD_NTRIES  10
 /* Percent of over-allocation (initial) */
-#define SD_MARGIN  10 
-/* 
+#define SD_MARGIN  10
+/*
  * Factor for over-allocation in percent (the margin is increased by this on
  * any failed try).
  */

Modified: stable/8/usr.bin/systat/icmp.c
==============================================================================
--- stable/8/usr.bin/systat/icmp.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/icmp.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -142,7 +142,7 @@ domode(struct icmpstat *ret)
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: stable/8/usr.bin/systat/icmp6.c
==============================================================================
--- stable/8/usr.bin/systat/icmp6.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/icmp6.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -141,7 +141,7 @@ domode(struct icmp6stat *ret)
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: stable/8/usr.bin/systat/ifcmds.c
==============================================================================
--- stable/8/usr.bin/systat/ifcmds.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/ifcmds.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -47,7 +47,7 @@ ifcmd(const char *cmd, const char *args)
 			clrtoeol();
 			addstr("what scale? ");
 			addstr(get_helplist());
-		} 
+		}
 	}
 	return (1);
 }

Modified: stable/8/usr.bin/systat/ifstat.c
==============================================================================
--- stable/8/usr.bin/systat/ifstat.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/ifstat.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -43,7 +43,7 @@
 #include "extern.h"
 #include "convtbl.h"
 
-                                /* Column numbers */
+				/* Column numbers */
 
 #define C1	0		/*  0-19 */
 #define C2	20		/* 20-39 */
@@ -121,9 +121,9 @@ static	 u_int getifnum(void);
 } while (0)
 
 #define DOPUTTOTAL(c, r, d)	do {					\
- 	CLEAR_COLUMN((r), (c));						\
- 	mvprintw((r), (c), "%12.3f %s  ",				\
- 		 convert(d##_##c, SC_AUTO),				\
+	CLEAR_COLUMN((r), (c));						\
+	mvprintw((r), (c), "%12.3f %s  ",				\
+		 convert(d##_##c, SC_AUTO),				\
 		 get_string(d##_##c, SC_AUTO));				\
 } while (0)
 
@@ -255,8 +255,8 @@ fetchifstat(void)
 		(void)getifmibdata(ifp->if_row, &ifp->if_mib);
 
 
-                new_inb = ifp->if_mib.ifmd_data.ifi_ibytes;
-                new_outb = ifp->if_mib.ifmd_data.ifi_obytes;
+		new_inb = ifp->if_mib.ifmd_data.ifi_ibytes;
+		new_outb = ifp->if_mib.ifmd_data.ifi_obytes;
 
 		/* Display interface if it's received some traffic. */
 		if (new_inb > 0 && old_inb == 0) {
@@ -269,9 +269,9 @@ fetchifstat(void)
 		 * for our current traffic rates, and while we're there,
 		 * see if we have new peak rates.
 		 */
-                old_tv = ifp->tv;
-                timersub(&new_tv, &old_tv, &tv);
-                elapsed = tv.tv_sec + (tv.tv_usec * 1e-6);
+		old_tv = ifp->tv;
+		timersub(&new_tv, &old_tv, &tv);
+		elapsed = tv.tv_sec + (tv.tv_usec * 1e-6);
 
 		ifp->if_in_curtraffic = new_inb - old_inb;
 		ifp->if_out_curtraffic = new_outb - old_outb;
@@ -281,8 +281,8 @@ fetchifstat(void)
 		 * and line, we divide by ``elapsed'' as this is likely
 		 * to be more accurate.
 		 */
-                ifp->if_in_curtraffic /= elapsed;
-                ifp->if_out_curtraffic /= elapsed;
+		ifp->if_in_curtraffic /= elapsed;
+		ifp->if_out_curtraffic /= elapsed;
 
 		if (ifp->if_in_curtraffic > ifp->if_in_traffic_peak)
 			ifp->if_in_traffic_peak = ifp->if_in_curtraffic;

Modified: stable/8/usr.bin/systat/ip.c
==============================================================================
--- stable/8/usr.bin/systat/ip.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/ip.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -150,7 +150,7 @@ domode(struct stat *ret)
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: stable/8/usr.bin/systat/ip6.c
==============================================================================
--- stable/8/usr.bin/systat/ip6.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/ip6.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -146,7 +146,7 @@ domode(struct ip6stat *ret)
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: stable/8/usr.bin/systat/keyboard.c
==============================================================================
--- stable/8/usr.bin/systat/keyboard.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/keyboard.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -39,88 +39,147 @@ __FBSDID("$FreeBSD$");
 static const char sccsid[] = "@(#)keyboard.c	8.1 (Berkeley) 6/6/93";
 #endif
 
+#include <sys/select.h>
+#include <sys/time.h>
+
 #include <errno.h>
 #include <ctype.h>
-#include <signal.h>
 #include <stdlib.h>
 #include <termios.h>
+#include <unistd.h>
 
 #include "systat.h"
 #include "extern.h"
 
+static char line[80];
+static int keyboard_dispatch(int ch);
+
 int
 keyboard(void)
 {
-        char ch, line[80];
-	int oldmask;
+	char line[80];
+	int ch, n;
+	struct timeval last, intvl, now, tm;
+	fd_set rfds;
+
+	/* Set initial timings */
+	gettimeofday(&last, NULL);
+	intvl.tv_sec = delay / 1000000;
+	intvl.tv_usec = delay % 1000000;
+	for (;;) {
+		col = 0;
+		move(CMDLINE, 0);
+		for (;;) {
+			/* Determine interval to sleep */
+			(void)gettimeofday(&now, NULL);
+			tm.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec;
+			tm.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec;
+			while (tm.tv_usec < 0) {
+				tm.tv_usec += 1000000;
+				tm.tv_sec--;
+			}
+			while (tm.tv_usec >= 1000000) {
+				tm.tv_usec -= 1000000;
+				tm.tv_sec++;
+			}
+			if (tm.tv_sec < 0) {
+				/* We have to update screen immediately */
+				display();
+				gettimeofday(&last, NULL);
+				continue;
+			}
+
+			/* Prepare select  */
+			FD_ZERO(&rfds);
+			FD_SET(STDIN_FILENO, &rfds);
+			n = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tm);
 
-        for (;;) {
-                col = 0;
-                move(CMDLINE, 0);
-                do {
-                        refresh();
-                        ch = getch();
-                        if (ch == ERR) {
-                                if (errno == EINTR)
-                                        continue;
-                                exit(1);
-                        }
-                        if (ch >= 'A' && ch <= 'Z')
-                                ch += 'a' - 'A';
-                        if (col == 0) {
-#define	mask(s)	(1 << ((s) - 1))
-                                if (ch == CTRL('l')) {
-					oldmask = sigblock(mask(SIGALRM));
-					wrefresh(curscr);
-					sigsetmask(oldmask);
-                                        continue;
-                                }
-				if (ch == CTRL('g')) {
-					oldmask = sigblock(mask(SIGALRM));
-					status();
-					sigsetmask(oldmask);
+			if (n > 0) {
+				/* Read event on stdin */
+				ch = getch();
+
+				if (keyboard_dispatch(ch) == 0) {
+					refresh();
 					continue;
 				}
-                                if (ch != ':')
-                                        continue;
-                                move(CMDLINE, 0);
-                                clrtoeol();
-                        }
-                        if (ch == erasechar() && col > 0) {
-                                if (col == 1 && line[0] == ':')
-                                        continue;
-                                col--;
-                                goto doerase;
-                        }
-                        if (ch == CTRL('w') && col > 0) {
-                                while (--col >= 0 && isspace(line[col]))
-                                        ;
-                                col++;
-                                while (--col >= 0 && !isspace(line[col]))
-                                        if (col == 0 && line[0] == ':')
-                                                break;
-                                col++;
-                                goto doerase;
-                        }
-                        if (ch == killchar() && col > 0) {
-                                col = 0;
-                                if (line[0] == ':')
-                                        col++;
-                doerase:
-                                move(CMDLINE, col);
-                                clrtoeol();
-                                continue;
-                        }
-                        if (isprint(ch) || ch == ' ') {
-                                line[col] = ch;
-                                mvaddch(CMDLINE, col, ch);
-                                col++;
-                        }
-                } while (col == 0 || (ch != '\r' && ch != '\n'));
-                line[col] = '\0';
-		oldmask = sigblock(mask(SIGALRM));
-                command(line + 1);
-		sigsetmask(oldmask);
-        }
-	/*NOTREACHED*/
+	
+				line[col] = '\0';
+				command(line + 1);
+				/* Refresh delay */
+				intvl.tv_sec = delay / 1000000;
+				intvl.tv_usec = delay % 1000000;
+				refresh();
+				break;
+			}
+
+			if (n < 0 && errno != EINTR)
+				exit(1);
+
+			/* Timeout or signal. Call display another time */
+			display();
+			gettimeofday(&last, NULL);
+		}
+	}
+}
+
+static int
+keyboard_dispatch(int ch)
+{
+
+	if (ch == ERR) {
+		if (errno == EINTR)
+			return 0;
+		exit(1);
+	}
+	if (ch >= 'A' && ch <= 'Z')
+		ch += 'a' - 'A';
+	if (col == 0) {
+		if (ch == CTRL('l')) {
+			wrefresh(curscr);
+			return 0;
+		}
+		if (ch == CTRL('g')) {
+			status();
+			return 0;
+		}
+		if (ch != ':')
+			return 0;
+		move(CMDLINE, 0);
+		clrtoeol();
+	}
+	if (ch == erasechar() && col > 0) {
+		if (col == 1 && line[0] == ':')
+			return 0;
+		col--;
+		goto doerase;
+	}
+	if (ch == CTRL('w') && col > 0) {
+		while (--col >= 0 && isspace(line[col]))
+			;
+		col++;
+		while (--col >= 0 && !isspace(line[col]))
+			if (col == 0 && line[0] == ':')
+				return 1;
+		col++;
+		goto doerase;
+	}
+	if (ch == killchar() && col > 0) {
+		col = 0;
+		if (line[0] == ':')
+			col++;
+doerase:
+		move(CMDLINE, col);
+		clrtoeol();
+		return 0;
+	}
+	if (isprint(ch) || ch == ' ') {
+		line[col] = ch;
+		mvaddch(CMDLINE, col, ch);
+		col++;
+	}
+
+	if (col == 0 || (ch != '\r' && ch != '\n'))
+		return 0;
+
+	return 1;
 }

Modified: stable/8/usr.bin/systat/main.c
==============================================================================
--- stable/8/usr.bin/systat/main.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/main.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -68,7 +68,7 @@ kvm_t *kd;
 sig_t	sigtstpdfl;
 double avenrun[3];
 int     col;
-int	naptime = 5;
+unsigned int	delay = 5000000;	/* in microseconds */
 int     verbose = 1;                    /* to report kvm read errs */
 struct	clockinfo clkinfo;
 double	hertz;
@@ -86,6 +86,7 @@ main(int argc, char **argv)
 {
 	char errbuf[_POSIX2_LINE_MAX], dummy;
 	size_t	size;
+	double t;
 
 	(void) setlocale(LC_ALL, "");
 
@@ -101,9 +102,9 @@ main(int argc, char **argv)
 				errx(1, "%s: unknown request", &argv[0][1]);
 			curcmd = p;
 		} else {
-			naptime = atoi(argv[0]);
-			if (naptime <= 0)
-				naptime = 5;
+			t = strtod(argv[0], NULL) * 1000000.0;
+			if (t > 0 && t < (double)UINT_MAX)
+				delay = (unsigned int)t;
 		}
 		argc--, argv++;
 	}
@@ -170,8 +171,7 @@ main(int argc, char **argv)
 
 	dellave = 0.0;
 
-	signal(SIGALRM, display);
-	display(0);
+	display();
 	noecho();
 	crmode();
 	keyboard();
@@ -196,7 +196,7 @@ labels(void)
 }
 
 void
-display(int signo __unused)
+display()
 {
 	int i, j;
 
@@ -227,7 +227,6 @@ display(int signo __unused)
 	wrefresh(wnd);
 	move(CMDLINE, col);
 	refresh();
-	alarm(naptime);
 }
 
 void

Modified: stable/8/usr.bin/systat/mode.c
==============================================================================
--- stable/8/usr.bin/systat/mode.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/mode.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -12,7 +12,7 @@
  * no representations about the suitability of this software for any
  * purpose.  It is provided "as is" without express or implied
  * warranty.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

Modified: stable/8/usr.bin/systat/mode.h
==============================================================================
--- stable/8/usr.bin/systat/mode.h	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/mode.h	Fri Nov 30 00:13:31 2012	(r243684)
@@ -12,7 +12,7 @@
  * no representations about the suitability of this software for any
  * purpose.  It is provided "as is" without express or implied
  * warranty.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

Modified: stable/8/usr.bin/systat/netstat.c
==============================================================================
--- stable/8/usr.bin/systat/netstat.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/netstat.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -133,7 +133,7 @@ closenetstat(WINDOW *w)
 			lastrow--;
 		p->ni_line = -1;
 	}
-        if (w != NULL) {
+	if (w != NULL) {
 		wclear(w);
 		wrefresh(w);
 		delwin(w);

Modified: stable/8/usr.bin/systat/systat.1
==============================================================================
--- stable/8/usr.bin/systat/systat.1	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/systat.1	Fri Nov 30 00:13:31 2012	(r243684)
@@ -32,7 +32,7 @@
 .\"	@(#)systat.1	8.2 (Berkeley) 12/30/93
 .\" $FreeBSD$
 .\"
-.Dd October 14, 2007
+.Dd September 17, 2012
 .Dt SYSTAT 1
 .Os
 .Sh NAME
@@ -113,6 +113,7 @@ full detail below.
 The
 .Ar refresh-value
 specifies the screen refresh time interval in seconds.
+Time interval can be fractional.
 .El
 .Pp
 Certain characters cause immediate action by

Modified: stable/8/usr.bin/systat/systat.h
==============================================================================
--- stable/8/usr.bin/systat/systat.h	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/systat.h	Fri Nov 30 00:13:31 2012	(r243684)
@@ -37,10 +37,10 @@
 #include <curses.h>
 
 struct  cmdtab {
-        const char *c_name;		/* command name */
-        void    (*c_refresh)(void);	/* display refresh */
-        void    (*c_fetch)(void);	/* sets up data structures */
-        void    (*c_label)(void);	/* label display */
+	const char *c_name;		/* command name */
+	void	(*c_refresh)(void);	/* display refresh */
+	void	(*c_fetch)(void);	/* sets up data structures */
+	void	(*c_label)(void);	/* label display */
 	int	(*c_init)(void);	/* initialize namelist, etc. */
 	WINDOW	*(*c_open)(void);	/* open display */
 	void	(*c_close)(WINDOW *);	/* close display */

Modified: stable/8/usr.bin/systat/tcp.c
==============================================================================
--- stable/8/usr.bin/systat/tcp.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/tcp.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -151,7 +151,7 @@ domode(struct tcpstat *ret)
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: stable/8/usr.bin/systat/vmstat.c
==============================================================================
--- stable/8/usr.bin/systat/vmstat.c	Thu Nov 29 21:26:57 2012	(r243683)
+++ stable/8/usr.bin/systat/vmstat.c	Fri Nov 30 00:13:31 2012	(r243684)
@@ -236,7 +236,7 @@ initkre(void)
 		intrloc = calloc(nintr, sizeof (long));
 		intrname = calloc(nintr, sizeof (char *));
 		intrnamebuf = sysctl_dynread("hw.intrnames", NULL);
-		if (intrnamebuf == NULL || intrname == NULL || 
+		if (intrnamebuf == NULL || intrname == NULL ||
 		    intrloc == NULL) {
 			error("Out of memory");
 			if (intrnamebuf)
@@ -863,7 +863,7 @@ dinfo(int dn, int lc, struct statinfo *n
 		elapsed_time = now->snap_time - then->snap_time;
 	} else {
 		/* Calculate relative to device creation */
-	        elapsed_time = now->snap_time - devstat_compute_etime(
+		elapsed_time = now->snap_time - devstat_compute_etime(
 		    &now->dinfo->devices[di].creation_time, NULL);
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211300013.qAU0DWa1081430>