Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/envstat Update userland envstat(8) to handle new {h...



details:   https://anonhg.NetBSD.org/src/rev/711c166c4827
branches:  trunk
changeset: 752113:711c166c4827
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Feb 15 22:37:14 2010 +0000

description:
Update userland envstat(8) to handle new {high,maximum}-capacity limits.

diffstat:

 usr.sbin/envstat/config.c     |  60 +++++++++++++++++++++++++++++++++++++++++-
 usr.sbin/envstat/config_lex.l |   6 ++--
 usr.sbin/envstat/envstat.c    |  27 ++++++++++++------
 3 files changed, 79 insertions(+), 14 deletions(-)

diffs (192 lines):

diff -r cfe50bdb9f89 -r 711c166c4827 usr.sbin/envstat/config.c
--- a/usr.sbin/envstat/config.c Mon Feb 15 22:32:04 2010 +0000
+++ b/usr.sbin/envstat/config.c Mon Feb 15 22:37:14 2010 +0000
@@ -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");
diff -r cfe50bdb9f89 -r 711c166c4827 usr.sbin/envstat/config_lex.l
--- a/usr.sbin/envstat/config_lex.l     Mon Feb 15 22:32:04 2010 +0000
+++ b/usr.sbin/envstat/config_lex.l     Mon Feb 15 22:37:14 2010 +0000
@@ -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]*
 
diff -r cfe50bdb9f89 -r 711c166c4827 usr.sbin/envstat/envstat.c
--- a/usr.sbin/envstat/envstat.c        Mon Feb 15 22:32:04 2010 +0000
+++ b/usr.sbin/envstat/envstat.c        Mon Feb 15 22:37:14 2010 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index