From 74999bdda45263582a97d18fc65600afa433db5c Mon Sep 17 00:00:00 2001 From: pgoyette Date: Mon, 15 Feb 2010 22:37:14 +0000 Subject: [PATCH] Update userland envstat(8) to handle new {high,maximum}-capacity limits. --- 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(-) diff --git a/usr.sbin/envstat/config.c b/usr.sbin/envstat/config.c index 4225ab9dad55..b02d7ec8f907 100644 --- a/usr.sbin/envstat/config.c +++ b/usr.sbin/envstat/config.c @@ -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 #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 @@ -501,6 +501,62 @@ config_devblock_check_sensorprops(prop_dictionary_t ksdict, config_errmsg(PROP_ERR, "warning-capacity", sensor); } + /* + * 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? */ diff --git a/usr.sbin/envstat/config_lex.l b/usr.sbin/envstat/config_lex.l index d1e9bf9bbf6a..ece3caf7f9c8 100644 --- a/usr.sbin/envstat/config_lex.l +++ b/usr.sbin/envstat/config_lex.l @@ -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 #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 @@ -49,7 +49,7 @@ int yylex(void); 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 --git a/usr.sbin/envstat/envstat.c b/usr.sbin/envstat/envstat.c index 6db8a40fa2c5..62b5ac1dc1c0 100644 --- a/usr.sbin/envstat/envstat.c +++ b/usr.sbin/envstat/envstat.c @@ -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 #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 @@ -64,10 +64,8 @@ typedef struct envsys_sensor { 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 @@ find_sensors(prop_array_t array, const char *dvname, dvprops_t edp) 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 @@ find_sensors(prop_array_t array, const char *dvname, dvprops_t edp) /* 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 @@ find_sensors(prop_array_t array, const char *dvname, dvprops_t edp) /* 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 @@ do { \ 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);