[Midnightbsd-cvs] src [7536] trunk/usr.bin/systat: re-add sensors framework support to systat.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu Apr 14 19:45:38 EDT 2016


Revision: 7536
          http://svnweb.midnightbsd.org/src/?rev=7536
Author:   laffer1
Date:     2016-04-14 19:45:38 -0400 (Thu, 14 Apr 2016)
Log Message:
-----------
re-add sensors framework support to systat. also sync with freebsd 9 stable functionality

Modified Paths:
--------------
    trunk/usr.bin/systat/Makefile
    trunk/usr.bin/systat/cmds.c
    trunk/usr.bin/systat/cmdtab.c
    trunk/usr.bin/systat/extern.h
    trunk/usr.bin/systat/icmp.c
    trunk/usr.bin/systat/icmp6.c
    trunk/usr.bin/systat/ip.c
    trunk/usr.bin/systat/ip6.c
    trunk/usr.bin/systat/keyboard.c
    trunk/usr.bin/systat/main.c
    trunk/usr.bin/systat/sensors.c
    trunk/usr.bin/systat/systat.1
    trunk/usr.bin/systat/tcp.c

Modified: trunk/usr.bin/systat/Makefile
===================================================================
--- trunk/usr.bin/systat/Makefile	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/Makefile	2016-04-14 23:45:38 UTC (rev 7536)
@@ -6,7 +6,7 @@
 PROG=	systat
 SRCS=	cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c \
 	mbufs.c netcmds.c netstat.c pigs.c swap.c icmp.c \
-	mode.c ip.c tcp.c \
+	mode.c ip.c sensors.c tcp.c \
 	vmstat.c convtbl.c ifcmds.c ifstat.c
 
 .if ${MK_INET6_SUPPORT} != "no"

Modified: trunk/usr.bin/systat/cmds.c
===================================================================
--- trunk/usr.bin/systat/cmds.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/cmds.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -35,6 +35,8 @@
 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>
@@ -49,10 +51,9 @@
 {
 	struct cmdtab *p;
 	char *cp, *tmpstr, *tmpstr1;
-	int interval, omask;
+	double t;
 
 	tmpstr = tmpstr1 = strdup(cmd);
-	omask = sigblock(sigmask(SIGALRM));
 	for (cp = tmpstr1; *cp && !isspace(*cp); cp++)
 		;
 	if (*cp)
@@ -68,7 +69,7 @@
 		goto done;
 	}
 	if (strcmp(tmpstr1, "stop") == 0) {
-		alarm(0);
+		delay = 0;
 		mvaddstr(CMDLINE, 0, "Refresh disabled.");
 		clrtoeol();
 		goto done;
@@ -88,19 +89,23 @@
 		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);
+	if (t > 0) {
+		delay = (unsigned int)t;
+		display();
 		status();
 		goto done;
 	}
@@ -112,7 +117,6 @@
 	if (p) {
 		if (curcmd == p)
 			goto done;
-		alarm(0);
 		(*curcmd->c_close)(wnd);
 		curcmd->c_flags &= ~CF_INIT;
 		wnd = (*p->c_open)();
@@ -133,7 +137,7 @@
 		}
 		curcmd = p;
 		labels();
-		display(0);
+		display();
 		status();
 		goto done;
 	}
@@ -140,7 +144,6 @@
 	if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(tmpstr1, cp))
 		error("%s: Unknown command.", tmpstr1);
 done:
-	sigsetmask(omask);
 	free(tmpstr);
 }
 
@@ -177,7 +180,7 @@
 {
 
 	error("Showing %s, refresh every %d seconds.",
-	  curcmd->c_name, naptime);
+	  curcmd->c_name, delay / 1000000);
 }
 
 int

Modified: trunk/usr.bin/systat/cmdtab.c
===================================================================
--- trunk/usr.bin/systat/cmdtab.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/cmdtab.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -78,6 +78,9 @@
 	{ "ifstat",	showifstat,	fetchifstat,	labelifstat,
 	  initifstat,	openifstat,	closeifstat,	cmdifstat,
 	  0,		CF_LOADAV },
+	{ "sensors",	showsensors,	fetchsensors,	labelsensors,
+	  initsensors,	opensensors,	closesensors,	0,
+	  0,		CF_LOADAV },
 	{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0 }
 };
 struct  cmdtab *curcmd = &cmdtab[0];

Modified: trunk/usr.bin/systat/extern.h
===================================================================
--- trunk/usr.bin/systat/extern.h	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/extern.h	2016-04-14 23:45:38 UTC (rev 7536)
@@ -49,11 +49,12 @@
 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;
 
@@ -78,6 +79,7 @@
 void	 closembufs(WINDOW *);
 void	 closenetstat(WINDOW *);
 void	 closepigs(WINDOW *);
+void	 closesensors(WINDOW *);
 void	 closeswap(WINDOW *);
 void	 closetcp(WINDOW *);
 int	 cmdifstat(const char *, const char *);
@@ -87,7 +89,7 @@
 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);
@@ -101,6 +103,7 @@
 void	 fetchmbufs(void);
 void	 fetchnetstat(void);
 void	 fetchpigs(void);
+void	 fetchsensors(void);
 void	 fetchswap(void);
 void	 fetchtcp(void);
 void	 getsysctl(const char *, void *, size_t);
@@ -115,6 +118,7 @@
 int	 initmbufs(void);
 int	 initnetstat(void);
 int	 initpigs(void);
+int	 initsensors(void);
 int	 initswap(void);
 int	 inittcp(void);
 int	 keyboard(void);
@@ -130,6 +134,7 @@
 void	 labelnetstat(void);
 void	 labelpigs(void);
 void	 labels(void);
+void	 labelsensors(void);
 void	 labelswap(void);
 void	 labeltcp(void);
 void	 load(void);
@@ -145,6 +150,7 @@
 WINDOW	*openmbufs(void);
 WINDOW	*opennetstat(void);
 WINDOW	*openpigs(void);
+WINDOW	*opensensors(void);
 WINDOW	*openswap(void);
 WINDOW	*opentcp(void);
 int	 prefix(const char *, const char *);
@@ -163,6 +169,7 @@
 void	 showmbufs(void);
 void	 shownetstat(void);
 void	 showpigs(void);
+void	 showsensors(void);
 void	 showswap(void);
 void	 showtcp(void);
 void	 status(void);

Modified: trunk/usr.bin/systat/icmp.c
===================================================================
--- trunk/usr.bin/systat/icmp.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/icmp.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -138,7 +138,7 @@
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: trunk/usr.bin/systat/icmp6.c
===================================================================
--- trunk/usr.bin/systat/icmp6.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/icmp6.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -137,7 +137,7 @@
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: trunk/usr.bin/systat/ip.c
===================================================================
--- trunk/usr.bin/systat/ip.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/ip.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -146,7 +146,7 @@
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: trunk/usr.bin/systat/ip6.c
===================================================================
--- trunk/usr.bin/systat/ip6.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/ip6.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -142,7 +142,7 @@
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;

Modified: trunk/usr.bin/systat/keyboard.c
===================================================================
--- trunk/usr.bin/systat/keyboard.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/keyboard.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -35,88 +35,146 @@
 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 line[80];
-	int ch, oldmask;
+	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);
-		do {
-			refresh();
-			ch = getch();
-			if (ch == ERR) {
-				if (errno == EINTR)
-					continue;
-				exit(1);
+		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--;
 			}
-			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);
-					continue;
-				}
-				if (ch != ':')
-					continue;
-				move(CMDLINE, 0);
-				clrtoeol();
+			while (tm.tv_usec >= 1000000) {
+				tm.tv_usec -= 1000000;
+				tm.tv_sec++;
 			}
-			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();
+			if (tm.tv_sec < 0) {
+				/* We have to update screen immediately */
+				display();
+				gettimeofday(&last, NULL);
 				continue;
 			}
-			if (isprint(ch) || ch == ' ') {
-				line[col] = ch;
-				mvaddch(CMDLINE, col, ch);
-				col++;
+
+			/* Prepare select  */
+			FD_ZERO(&rfds);
+			FD_SET(STDIN_FILENO, &rfds);
+			n = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tm);
+
+			if (n > 0) {
+				/* Read event on stdin */
+				ch = getch();
+
+				if (keyboard_dispatch(ch) == 0) {
+					refresh();
+					continue;
+				}
+	
+				line[col] = '\0';
+				command(line + 1);
+				/* Refresh delay */
+				intvl.tv_sec = delay / 1000000;
+				intvl.tv_usec = delay % 1000000;
+				refresh();
+				break;
 			}
-		} while (col == 0 || (ch != '\r' && ch != '\n'));
-		line[col] = '\0';
-		oldmask = sigblock(mask(SIGALRM));
-		command(line + 1);
-		sigsetmask(oldmask);
+
+			if (n < 0 && errno != EINTR)
+				exit(1);
+
+			/* Timeout or signal. Call display another time */
+			display();
+			gettimeofday(&last, NULL);
+		}
 	}
-	/*NOTREACHED*/
 }
+
+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: trunk/usr.bin/systat/main.c
===================================================================
--- trunk/usr.bin/systat/main.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/main.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -64,7 +64,7 @@
 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;
@@ -82,6 +82,7 @@
 {
 	char errbuf[_POSIX2_LINE_MAX], dummy;
 	size_t	size;
+	double t;
 
 	(void) setlocale(LC_ALL, "");
 
@@ -97,9 +98,9 @@
 				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++;
 	}
@@ -166,8 +167,7 @@
 
 	dellave = 0.0;
 
-	signal(SIGALRM, display);
-	display(0);
+	display();
 	noecho();
 	crmode();
 	keyboard();
@@ -192,7 +192,7 @@
 }
 
 void
-display(int signo __unused)
+display()
 {
 	int i, j;
 
@@ -223,7 +223,6 @@
 	wrefresh(wnd);
 	move(CMDLINE, col);
 	refresh();
-	alarm(naptime);
 }
 
 void

Modified: trunk/usr.bin/systat/sensors.c
===================================================================
--- trunk/usr.bin/systat/sensors.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/sensors.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -21,7 +21,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$FreeBSD: src/usr.bin/systat/sensors.c,v 1.1 2007/10/14 10:45:31 netchild Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>

Modified: trunk/usr.bin/systat/systat.1
===================================================================
--- trunk/usr.bin/systat/systat.1	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/systat.1	2016-04-14 23:45:38 UTC (rev 7536)
@@ -28,7 +28,7 @@
 .\"	@(#)systat.1	8.2 (Berkeley) 12/30/93
 .\" $MidnightBSD$
 .\"
-.Dd October 14, 2007
+.Dd September 17, 2012
 .Dt SYSTAT 1
 .Os
 .Sh NAME
@@ -97,6 +97,7 @@
 .Ic mbufs ,
 .Ic netstat ,
 .Ic pigs ,
+.Ic sensors ,
 .Ic swap ,
 .Ic tcp ,
 or
@@ -109,6 +110,7 @@
 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
@@ -282,6 +284,11 @@
 .It Ic mbufs
 Display, in the lower window, the number of mbufs allocated
 for particular uses, i.e., data, socket structures, etc.
+.It Ic sensors
+Display, in the lower window,
+the current values of available hardware sensors,
+in a format similar to that of
+.Xr sysctl 8 .
 .It Ic vmstat
 Take over the entire display and show a (rather crowded) compendium
 of statistics related to virtual memory usage, process scheduling,
@@ -603,6 +610,7 @@
 .Xr udp 4 ,
 .Xr gstat 8 ,
 .Xr iostat 8 ,
+.Xr sysctl 8 ,
 .Xr vmstat 8
 .Sh HISTORY
 The

Modified: trunk/usr.bin/systat/tcp.c
===================================================================
--- trunk/usr.bin/systat/tcp.c	2016-04-14 23:30:08 UTC (rev 7535)
+++ trunk/usr.bin/systat/tcp.c	2016-04-14 23:45:38 UTC (rev 7536)
@@ -147,7 +147,7 @@
 	switch(currentmode) {
 	case display_RATE:
 		sub = &oldstat;
-		divisor = naptime;
+		divisor = (delay > 1000000) ? delay / 1000000 : 1;
 		break;
 	case display_DELTA:
 		sub = &oldstat;



More information about the Midnightbsd-cvs mailing list