Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/envstat For raw output (-x) allow to extract indivi...
details: https://anonhg.NetBSD.org/src/rev/7bc379822e44
branches: trunk
changeset: 1016258:7bc379822e44
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sat Nov 14 09:11:55 2020 +0000
description:
For raw output (-x) allow to extract individual properties like drvctl -p.
E.g.
# envstat -x /vcmbox0/0/cur-value
328150000
diffstat:
usr.sbin/envstat/config.c | 83 ++++++++++++++++++++++++++++++++++++++++++++-
usr.sbin/envstat/envstat.8 | 6 ++-
usr.sbin/envstat/envstat.c | 13 ++++--
usr.sbin/envstat/envstat.h | 3 +-
4 files changed, 96 insertions(+), 9 deletions(-)
diffs (205 lines):
diff -r 55452650ce52 -r 7bc379822e44 usr.sbin/envstat/config.c
--- a/usr.sbin/envstat/config.c Sat Nov 14 07:36:00 2020 +0000
+++ b/usr.sbin/envstat/config.c Sat Nov 14 09:11:55 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.13 2020/06/07 00:51:48 thorpej Exp $ */
+/* $NetBSD: config.c,v 1.14 2020/11/14 09:11:55 mlelstv Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -27,9 +27,11 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: config.c,v 1.13 2020/06/07 00:51:48 thorpej Exp $");
+__RCSID("$NetBSD: config.c,v 1.14 2020/11/14 09:11:55 mlelstv Exp $");
#endif /* not lint */
+#include <inttypes.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -134,7 +136,7 @@
}
/*
- * Only used for debugging purposses.
+ * Show raw data
*/
void
config_dict_dump(prop_dictionary_t d)
@@ -146,6 +148,81 @@
free(buf);
}
+static void
+display_object(prop_object_t obj, bool nflag)
+{
+ char *xml;
+ prop_object_t next_obj;
+ prop_object_iterator_t iter;
+
+ if (obj == NULL)
+ exit(EXIT_FAILURE);
+ switch (prop_object_type(obj)) {
+ case PROP_TYPE_BOOL:
+ printf("%s\n", prop_bool_true(obj) ? "true" : "false");
+ break;
+ case PROP_TYPE_NUMBER:
+ printf("%" PRId64 "\n", prop_number_signed_value(obj));
+ break;
+ case PROP_TYPE_STRING:
+ printf("%s\n", prop_string_value(obj));
+ break;
+ case PROP_TYPE_DICTIONARY:
+ xml = prop_dictionary_externalize(obj);
+ printf("%s", xml);
+ free(xml);
+ break;
+ case PROP_TYPE_ARRAY:
+ iter = prop_array_iterator(obj);
+ if (!nflag)
+ printf("Array:\n");
+ while ((next_obj = prop_object_iterator_next(iter)) != NULL)
+ display_object(next_obj, nflag);
+ break;
+ default:
+ errx(EXIT_FAILURE, "Unhandled type %d", prop_object_type(obj));
+ }
+}
+
+void
+config_dict_extract(prop_dictionary_t dict, const char *prop, bool nflag)
+{
+ char *s, *p, *cur, *ep = NULL;
+ prop_object_t obj;
+ unsigned long ind;
+
+ obj = dict;
+ cur = NULL;
+ s = strdup(prop);
+ p = strtok_r(s, "/", &ep);
+ while (p) {
+ cur = p;
+ p = strtok_r(NULL, "/", &ep);
+
+ switch (prop_object_type(obj)) {
+ case PROP_TYPE_DICTIONARY:
+ obj = prop_dictionary_get(obj, cur);
+ if (obj == NULL)
+ exit(EXIT_FAILURE);
+ break;
+ case PROP_TYPE_ARRAY:
+ ind = strtoul(cur, NULL, 0);
+ obj = prop_array_get(obj, ind);
+ if (obj == NULL)
+ exit(EXIT_FAILURE);
+ break;
+ default:
+ errx(EXIT_FAILURE, "Select neither dict nor array with"
+ " `%s'", cur);
+ }
+ }
+
+ if (obj != NULL && cur != NULL)
+ display_object(obj, nflag);
+
+ free(s);
+}
+
/*
* Returns the global dictionary.
*/
diff -r 55452650ce52 -r 7bc379822e44 usr.sbin/envstat/envstat.8
--- a/usr.sbin/envstat/envstat.8 Sat Nov 14 07:36:00 2020 +0000
+++ b/usr.sbin/envstat/envstat.8 Sat Nov 14 09:11:55 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: envstat.8,v 1.62 2014/05/18 11:46:24 kardel Exp $
+.\" $NetBSD: envstat.8,v 1.63 2020/11/14 09:11:55 mlelstv Exp $
.\"
.\" Copyright (c) 2000, 2007, 2008, 2009, 2014 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -41,6 +41,7 @@
.Op Fl i Ar interval
.Op Fl s Ar "device:sensor,..."
.Op Fl w Ar width
+.Op Ar property...
.Sh DESCRIPTION
.Nm
is a utility that handles various aspects of the sensors
@@ -139,6 +140,9 @@
.Xr sysmon_envsys 9
framework that contains details about all registered devices
and sensors.
+If
+.Ar property
+is specified, the value of that property is printed.
.El
.Sh UNITS
The display mode may show some values with abbreviated units;
diff -r 55452650ce52 -r 7bc379822e44 usr.sbin/envstat/envstat.c
--- a/usr.sbin/envstat/envstat.c Sat Nov 14 07:36:00 2020 +0000
+++ b/usr.sbin/envstat/envstat.c Sat Nov 14 09:11:55 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: envstat.c,v 1.97 2020/06/07 00:51:48 thorpej Exp $ */
+/* $NetBSD: envstat.c,v 1.98 2020/11/14 09:11:55 mlelstv Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: envstat.c,v 1.97 2020/06/07 00:51:48 thorpej Exp $");
+__RCSID("$NetBSD: envstat.c,v 1.98 2020/11/14 09:11:55 mlelstv Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -192,7 +192,7 @@
argc -= optind;
argv += optind;
- if (argc > 0)
+ if (argc > 0 && (flags & ENVSYS_XFLAG) == 0)
usage();
/* Check if we want to make statistics */
@@ -219,7 +219,11 @@
if (rval)
errx(EXIT_FAILURE, "%s", strerror(rval));
- config_dict_dump(dict);
+ if (argc > 0) {
+ for (; argc > 0; ++argv, --argc)
+ config_dict_extract(dict, *argv, true);
+ } else
+ config_dict_dump(dict);
/* Remove all properties set in dictionary */
} else if (flags & ENVSYS_SFLAG) {
@@ -1098,6 +1102,7 @@
(void)fprintf(stderr, "Usage: %s [-DfIklrSTx] ", getprogname());
(void)fprintf(stderr, "[-c file] [-d device] [-i interval] ");
(void)fprintf(stderr, "[-s device:sensor,...] [-w width]\n");
+ (void)fprintf(stderr, " %s -x [property]", getprogname());
exit(EXIT_FAILURE);
/* NOTREACHED */
}
diff -r 55452650ce52 -r 7bc379822e44 usr.sbin/envstat/envstat.h
--- a/usr.sbin/envstat/envstat.h Sat Nov 14 07:36:00 2020 +0000
+++ b/usr.sbin/envstat/envstat.h Sat Nov 14 09:11:55 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: envstat.h,v 1.3 2020/06/07 00:51:48 thorpej Exp $ */
+/* $NetBSD: envstat.h,v 1.4 2020/11/14 09:11:55 mlelstv Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -47,6 +47,7 @@
void config_dict_adddev_prop(const char *, const char *, int);
void config_dict_destroy(prop_dictionary_t);
void config_dict_dump(prop_dictionary_t);
+void config_dict_extract(prop_dictionary_t, const char *, bool);
void config_dict_fulldump(void);
void config_dict_mark(void);
prop_dictionary_t config_dict_parsed(void);
Home |
Main Index |
Thread Index |
Old Index