Module Name: src
Committed By: pgoyette
Date: Mon Feb 15 22:37:14 UTC 2010
Modified Files:
src/usr.sbin/envstat: config.c config_lex.l envstat.c
Log Message:
Update userland envstat(8) to handle new {high,maximum}-capacity limits.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/envstat/config.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/envstat/config_lex.l
cvs rdiff -u -r1.76 -r1.77 src/usr.sbin/envstat/envstat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/envstat/config.c
diff -u src/usr.sbin/envstat/config.c:1.8 src/usr.sbin/envstat/config.c:1.9
--- src/usr.sbin/envstat/config.c:1.8 Fri Aug 22 11:27:50 2008
+++ src/usr.sbin/envstat/config.c Mon Feb 15 22:37:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.8 2008/08/22 11:27:50 pgoyette Exp $ */
+/* $NetBSD: config.c,v 1.9 2010/02/15 22:37:14 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: config.c,v 1.8 2008/08/22 11:27:50 pgoyette Exp $");
+__RCSID("$NetBSD: config.c,v 1.9 2010/02/15 22:37:14 pgoyette Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -502,6 +502,62 @@
}
/*
+ * high-capacity property set?
+ */
+ obj = prop_dictionary_get(csdict, "high-capacity");
+ if (obj) {
+ obj2 = prop_dictionary_get(ksdict, "want-percentage");
+ obj3 = prop_dictionary_get(ksdict, "monitoring-supported");
+ if (prop_bool_true(obj2) && prop_bool_true(obj3)) {
+ strval = prop_string_cstring(obj);
+ val = strtod(strval, &endptr);
+ if ((*endptr != '\0') || (val < 0 || val > 100))
+ config_errmsg(VALUE_ERR,
+ "high-capacity",
+ sensor);
+ /*
+ * Convert the value to a valid percentage.
+ */
+ obj = prop_dictionary_get(ksdict, "max-value");
+ val = (val / 100) * prop_number_integer_value(obj);
+
+ if (!prop_dictionary_set_uint32(csdict,
+ "high-capacity",
+ val))
+ err(EXIT_FAILURE, "dict_set highcap");
+ } else
+ config_errmsg(PROP_ERR, "high-capacity", sensor);
+ }
+
+ /*
+ * maximum-capacity property set?
+ */
+ obj = prop_dictionary_get(csdict, "maximum-capacity");
+ if (obj) {
+ obj2 = prop_dictionary_get(ksdict, "want-percentage");
+ obj3 = prop_dictionary_get(ksdict, "monitoring-supported");
+ if (prop_bool_true(obj2) && prop_bool_true(obj3)) {
+ strval = prop_string_cstring(obj);
+ val = strtod(strval, &endptr);
+ if ((*endptr != '\0') || (val < 0 || val > 100))
+ config_errmsg(VALUE_ERR,
+ "maximum-capacity",
+ sensor);
+ /*
+ * Convert the value to a valid percentage.
+ */
+ obj = prop_dictionary_get(ksdict, "max-value");
+ val = (val / 100) * prop_number_integer_value(obj);
+
+ if (!prop_dictionary_set_uint32(csdict,
+ "maximum-capacity",
+ val))
+ err(EXIT_FAILURE, "dict_set maxcap");
+ } else
+ config_errmsg(PROP_ERR, "maximum-capacity", sensor);
+ }
+
+ /*
* critical-max property set?
*/
obj = prop_dictionary_get(csdict, "critical-max");
Index: src/usr.sbin/envstat/config_lex.l
diff -u src/usr.sbin/envstat/config_lex.l:1.6 src/usr.sbin/envstat/config_lex.l:1.7
--- src/usr.sbin/envstat/config_lex.l:1.6 Thu Oct 29 14:38:37 2009
+++ src/usr.sbin/envstat/config_lex.l Mon Feb 15 22:37:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: config_lex.l,v 1.6 2009/10/29 14:38:37 christos Exp $ */
+/* $NetBSD: config_lex.l,v 1.7 2010/02/15 22:37:14 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -29,7 +29,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: config_lex.l,v 1.6 2009/10/29 14:38:37 christos Exp $");
+__RCSID("$NetBSD: config_lex.l,v 1.7 2010/02/15 22:37:14 pgoyette Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -49,7 +49,7 @@
DEVICEPROP refresh-timeout
SENSOR sensor[0-9]+
-SENSORPROP warning-max|warning-min|warning-capacity|critical-max|critical-min|critical-capacity|rfact|description
+SENSORPROP warning-max|high-capacity|warning-min|warning-capacity|critical-max|maximum-capacity|critical-min|critical-capacity|rfact|description
SP_STRING [(+|\-)\$A-Za-z\.\/_\-0-9 ]*
STRING [\$A-Za-z\.\/_\-0-9]*
Index: src/usr.sbin/envstat/envstat.c
diff -u src/usr.sbin/envstat/envstat.c:1.76 src/usr.sbin/envstat/envstat.c:1.77
--- src/usr.sbin/envstat/envstat.c:1.76 Fri Feb 12 14:26:27 2010
+++ src/usr.sbin/envstat/envstat.c Mon Feb 15 22:37:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: envstat.c,v 1.76 2010/02/12 14:26:27 njoly Exp $ */
+/* $NetBSD: envstat.c,v 1.77 2010/02/15 22:37:14 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.76 2010/02/12 14:26:27 njoly Exp $");
+__RCSID("$NetBSD: envstat.c,v 1.77 2010/02/15 22:37:14 pgoyette Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -64,10 +64,8 @@
int32_t max_value;
int32_t min_value;
int32_t avg_value;
- int32_t critcap_value;
int32_t critmin_value;
int32_t critmax_value;
- int32_t warncap_value;
int32_t warnmin_value;
int32_t warnmax_value;
char desc[ENVSYS_DESCLEN];
@@ -567,6 +565,11 @@
if (obj1)
sensor->critmax_value = prop_number_integer_value(obj1);
+ /* get maximum capacity value if available */
+ obj1 = prop_dictionary_get(obj, "maximum-capacity");
+ if (obj1)
+ sensor->critmax_value = prop_number_integer_value(obj1);
+
/* get critical min value if available */
obj1 = prop_dictionary_get(obj, "critical-min");
if (obj1)
@@ -575,13 +578,18 @@
/* get critical capacity value if available */
obj1 = prop_dictionary_get(obj, "critical-capacity");
if (obj1)
- sensor->critcap_value = prop_number_integer_value(obj1);
+ sensor->critmin_value = prop_number_integer_value(obj1);
/* get warning max value if available */
obj1 = prop_dictionary_get(obj, "warning-max");
if (obj1)
sensor->warnmax_value = prop_number_integer_value(obj1);
+ /* get high capacity value if available */
+ obj1 = prop_dictionary_get(obj, "high-capacity");
+ if (obj1)
+ sensor->warnmax_value = prop_number_integer_value(obj1);
+
/* get warning min value if available */
obj1 = prop_dictionary_get(obj, "warning-min");
if (obj1)
@@ -590,7 +598,7 @@
/* get warning capacity value if available */
obj1 = prop_dictionary_get(obj, "warning-capacity");
if (obj1)
- sensor->warncap_value = prop_number_integer_value(obj1);
+ sensor->warnmin_value = prop_number_integer_value(obj1);
/* print sensor names if -l was given */
if (flags & ENVSYS_LFLAG) {
@@ -957,9 +965,10 @@
if (sensor->percentage) {
- ilen += 9 + 9;
- PRINTPCT(warncap_value);
- PRINTPCT(critcap_value);
+ PRINTPCT(critmax_value);
+ PRINTPCT(warnmax_value);
+ PRINTPCT(warnmin_value);
+ PRINTPCT(critmin_value);
} else {
PRINTVAL(critmax_value);