Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/envstat Since we never have both a limit value and ...
details: https://anonhg.NetBSD.org/src/rev/06ef87b2c1c8
branches: trunk
changeset: 751251:06ef87b2c1c8
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sat Jan 30 02:56:39 2010 +0000
description:
Since we never have both a limit value and a limit %capacity value,
remove the Capacity column.
Reduce inter-column spacing, and display all four limits on one page,
rather than using the -W command line option to switch between critical
and warning limits. (The -W option is still permitted, but has no
effect.)
%capacity limits are displayed in the WarnMin and CritMin columns, but
have a trailing % sign.
diffstat:
usr.sbin/envstat/envstat.8 | 7 +-
usr.sbin/envstat/envstat.c | 286 ++++++++++++++++++--------------------------
2 files changed, 118 insertions(+), 175 deletions(-)
diffs (truncated from 474 to 300 lines):
diff -r 358f0afbe1dc -r 06ef87b2c1c8 usr.sbin/envstat/envstat.8
--- a/usr.sbin/envstat/envstat.8 Sat Jan 30 02:46:52 2010 +0000
+++ b/usr.sbin/envstat/envstat.8 Sat Jan 30 02:56:39 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: envstat.8,v 1.51 2009/05/04 22:31:36 wiz Exp $
+.\" $NetBSD: envstat.8,v 1.52 2010/01/30 02:56:39 pgoyette Exp $
.\"
.\" Copyright (c) 2000, 2007, 2008, 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 14, 2009
+.Dd January 29, 2010
.Dt ENVSTAT 8
.Os
.Sh NAME
@@ -131,8 +131,7 @@
Each column is additionally separated by a single space.
The default is the length of the longest sensor name.
.It Fl W
-Display the warning alarm minimum and maximum levels instead of the critical
-alarm levels.
+This option has no effect. It is retained for historical reasons.
.It Fl x
Shows the property list used by the
.Xr sysmon_envsys 9
diff -r 358f0afbe1dc -r 06ef87b2c1c8 usr.sbin/envstat/envstat.c
--- a/usr.sbin/envstat/envstat.c Sat Jan 30 02:46:52 2010 +0000
+++ b/usr.sbin/envstat/envstat.c Sat Jan 30 02:56:39 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: envstat.c,v 1.72 2009/04/04 18:43:01 christos Exp $ */
+/* $NetBSD: envstat.c,v 1.73 2010/01/30 02:56:39 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: envstat.c,v 1.72 2009/04/04 18:43:01 christos Exp $");
+__RCSID("$NetBSD: envstat.c,v 1.73 2010/01/30 02:56:39 pgoyette Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -55,7 +55,6 @@
#define ENVSYS_IFLAG 0x00000010 /* skip invalid sensors */
#define ENVSYS_SFLAG 0x00000020 /* remove all properties set */
#define ENVSYS_TFLAG 0x00000040 /* make statistics */
-#define ENVSYS_WFLAG 0x00000080 /* print warn{min,max} values */
#define ENVSYS_KFLAG 0x00000100 /* show temp in kelvin */
/* Sensors */
@@ -175,9 +174,6 @@
case 'T': /* make statistics */
flags |= ENVSYS_TFLAG;
break;
- case 'W': /* print warn{max,min} vs crit{max,min} */
- flags |= ENVSYS_WFLAG;
- break;
case 'w': /* width value for the lines */
width = (unsigned int)strtoul(optarg, &endptr, 10);
if (*endptr != '\0')
@@ -186,6 +182,8 @@
case 'x': /* print the dictionary in raw format */
flags |= ENVSYS_XFLAG;
break;
+ case 'W': /* No longer used, retained for campatability */
+ break;
case '?':
default:
usage();
@@ -204,9 +202,6 @@
if (!interval)
errx(EXIT_FAILURE,
"-T cannot be used without an interval (-i)");
- if (flags & ENVSYS_WFLAG)
- errx(EXIT_FAILURE,
- "-T cannot be used with -W");
else
statistics = true;
}
@@ -440,11 +435,9 @@
goto out;
}
rval = check_sensors(str);
- if (rval) {
+ free(str);
+ if (rval)
free(str);
- goto out;
- }
- free(str);
}
if ((flags & ENVSYS_LFLAG) == 0 && (flags & ENVSYS_DFLAG) == 0)
print_sensors();
@@ -718,12 +711,12 @@
{
sensor_t sensor;
sensor_stats_t stats = NULL;
- size_t maxlen = 0, ilen = 32 + 3;
+ size_t maxlen = 0, ilen;
double temp = 0;
const char *invalid = "N/A", *degrees, *tmpstr, *stype;
- const char *a, *b, *c, *d, *units;
+ const char *a, *b, *c, *d, *e, *units;
- tmpstr = stype = d = NULL;
+ tmpstr = stype = d = e = NULL;
/* find the longest description */
SIMPLEQ_FOREACH(sensor, &sensors_list, entries)
@@ -747,21 +740,18 @@
b = "Max";
c = "Min";
d = "Avg";
- } else if (flags & ENVSYS_WFLAG) {
- b = "WarnMax";
- c = "WarnMin";
- d = "WarnCap";
} else {
b = "CritMax";
- c = "CritMin";
- d = "CritCap";
+ c = "WarnMax";
+ d = "WarnMin";
+ e = "CritMin";
}
if (!sensors || (!header_passes && sensors) ||
(header_passes == 10 && sensors)) {
- (void)printf("%s%*s %10s %8s %8s %8s %8s\n",
+ (void)printf("%s%*s %9s %8s %8s %8s %8s %4s\n",
mydevname ? "" : " ", (int)maxlen,
- "", a, b, c, d, units);
+ "", a, b, c, d, e, units);
if (sensors && header_passes == 10)
header_passes = 0;
}
@@ -801,7 +791,7 @@
/* print invalid string */
if (sensor->invalid) {
- (void)printf(": %10s\n", invalid);
+ (void)printf(": %9s\n", invalid);
continue;
}
@@ -811,146 +801,112 @@
if ((strcmp(sensor->type, "Indicator") == 0) ||
(strcmp(sensor->type, "Battery charge") == 0)) {
- (void)printf(": %10s", sensor->cur_value ? "ON" : "OFF");
+ (void)printf(":%10s", sensor->cur_value ? "ON" : "OFF");
-/* converts the value to degC or degF or keep in Kelvin */
-#define CONVERTTEMP(a, b, c) \
+/* convert and print a temp value in degC, degF, or Kelvin */
+#define PRINTTEMP(a) \
do { \
- if (b) \
- (a) = ((b) / 1000000.0); \
- if (flags & ENVSYS_FFLAG) { \
- if (b) \
- (a) = (a) * (9.0 / 5.0) - 459.67; \
- (c) = "degF"; \
- } else if (flags & ENVSYS_KFLAG) { \
- (c) = "K"; \
- } else { \
- if (b) \
- (a) = (a) - 273.15; \
- (c) = "degC"; \
- } \
+ if (a) { \
+ temp = ((a) / 1000000.0); \
+ if (flags & ENVSYS_FFLAG) { \
+ temp = temp * (9.0 / 5.0) - 459.67; \
+ degrees = "degF"; \
+ } else if (flags & ENVSYS_KFLAG) { \
+ degrees = "K"; \
+ } else { \
+ temp = temp - 273.15; \
+ degrees = "degC"; \
+ } \
+ (void)printf("%*.3f ", (int)ilen, temp); \
+ ilen = 8; \
+ } else \
+ ilen += 9; \
} while (/* CONSTCOND */ 0)
-
/* temperatures */
} else if (strcmp(sensor->type, "Temperature") == 0) {
- CONVERTTEMP(temp, sensor->cur_value, degrees);
+ ilen = 10;
+ degrees = "";
+ (void)printf(":");
+ PRINTTEMP(sensor->cur_value);
stype = degrees;
- (void)printf(": %10.3f ", temp);
+ ilen = 8;
if (statistics) {
/* show statistics if flag set */
- CONVERTTEMP(temp, stats->max, degrees);
- (void)printf("%8.3f ", temp);
- CONVERTTEMP(temp, stats->min, degrees);
- (void)printf("%8.3f ", temp);
- CONVERTTEMP(temp, stats->avg, degrees);
- (void)printf("%8.3f ", temp);
- ilen = 8;
- } else if (flags & ENVSYS_WFLAG) {
- if (sensor->warnmax_value) {
- CONVERTTEMP(temp,
- sensor->warnmax_value, degrees);
- (void)printf( "%8.3f ", temp);
- ilen = 24 + 2;
- }
-
- if (sensor->warnmin_value) {
- CONVERTTEMP(temp,
- sensor->warnmin_value, degrees);
- if (sensor->warnmax_value)
- ilen = 8;
- else
- ilen = 16 + 1;
-
- (void)printf("%*.3f ", (int)ilen, temp);
- ilen = 16 + 1;
- }
+ PRINTTEMP(stats->max);
+ PRINTTEMP(stats->min);
+ PRINTTEMP(stats->avg);
+ ilen += 9;
} else {
- if (sensor->critmax_value) {
- CONVERTTEMP(temp,
- sensor->critmax_value, degrees);
- (void)printf( "%8.3f ", temp);
- ilen = 24 + 2;
- }
-
- if (sensor->critmin_value) {
- CONVERTTEMP(temp,
- sensor->critmin_value, degrees);
- if (sensor->critmax_value)
- ilen = 8;
- else
- ilen = 16 + 1;
-
- (void)printf("%*.3f ", (int)ilen, temp);
- ilen = 16 + 1;
- }
+ PRINTTEMP(sensor->critmax_value);
+ PRINTTEMP(sensor->warnmax_value);
+ PRINTTEMP(sensor->warnmin_value);
+ PRINTTEMP(sensor->warnmax_value);
}
-
- (void)printf("%*s", (int)ilen, stype);
-#undef CONVERTTEMP
+ (void)printf("%*s", (int)ilen - 4, stype);
+#undef PRINTTEMP
/* fans */
} else if (strcmp(sensor->type, "Fan") == 0) {
stype = "RPM";
- (void)printf(": %10u ", sensor->cur_value);
+ (void)printf(":%10u ", sensor->cur_value);
+
+ ilen = 8;
if (statistics) {
/* show statistics if flag set */
(void)printf("%8u %8u %8u ",
stats->max, stats->min, stats->avg);
- ilen = 8;
- } else if (flags & ENVSYS_WFLAG) {
+ ilen += 9;
+ } else {
+ if (sensor->critmax_value) {
+ (void)printf("%*u ", (int)ilen,
+ sensor->critmax_value);
+ ilen = 8;
+ } else
+ ilen += 9;
+
if (sensor->warnmax_value) {
- (void)printf("%8u ",
+ (void)printf("%*u ", (int)ilen,
sensor->warnmax_value);
- ilen = 24 + 2;
- }
+ ilen = 8;
+ } else
+ ilen += 9;
if (sensor->warnmin_value) {
Home |
Main Index |
Thread Index |
Old Index