Module Name:    src
Committed By:   pgoyette
Date:           Mon Jan 16 19:43:50 UTC 2012

Modified Files:
        src/sbin/drvctl: drvctl.8 drvctl.c

Log Message:
Enhance drvctl -p processing to handle new autoconfig info in property
dictionaries.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sbin/drvctl/drvctl.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/drvctl/drvctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/drvctl/drvctl.8
diff -u src/sbin/drvctl/drvctl.8:1.12 src/sbin/drvctl/drvctl.8:1.13
--- src/sbin/drvctl/drvctl.8:1.12	Sun Aug  7 13:00:35 2011
+++ src/sbin/drvctl/drvctl.8	Mon Jan 16 19:43:50 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: drvctl.8,v 1.12 2011/08/07 13:00:35 jmcneill Exp $
+.\" $NetBSD: drvctl.8,v 1.13 2012/01/16 19:43:50 pgoyette Exp $
 .\"
 .\" Copyright (c) 2004
 .\" 	Matthias Drochner.  All rights reserved.
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 7, 2011
+.Dd January 16, 2012
 .Dt DRVCTL 8
 .Os
 .Sh NAME
@@ -44,6 +44,7 @@
 .Fl l
 .Op Ar device
 .Nm
+.Op Fl n
 .Fl p
 .Ar device
 .Op Ar property ...
@@ -72,6 +73,13 @@ attached to (and which defines the inter
 the locator information).
 This will only be needed in rare cases where the bus
 has multiple attributes.
+If there are multiple attributes, and one is not specified,
+.Nm
+will return an Invalid argument.
+In such cases, the
+.Fl p
+option can be used to determine the available interface
+attributes.
 .It Fl d
 Detach the device driver from the device given by the
 .Ar device
@@ -96,6 +104,9 @@ The second column is the child.
 Suppress first column in
 .Fl l
 output.
+Suppress non-XML headers in
+.Fl p
+output.
 .It Fl p
 Get properties for the device specified by the
 .Ar device
@@ -143,4 +154,4 @@ output.
 Currently, there is no good way to get information about locator
 lengths and default values (which is present at kernel configuration
 time) out of a running kernel.
-Thus the locator handling is less intelligent as it could be.
+Thus the locator handling is less intelligent than it could be.

Index: src/sbin/drvctl/drvctl.c
diff -u src/sbin/drvctl/drvctl.c:1.14 src/sbin/drvctl/drvctl.c:1.15
--- src/sbin/drvctl/drvctl.c:1.14	Wed Oct 19 22:13:46 2011
+++ src/sbin/drvctl/drvctl.c	Mon Jan 16 19:43:50 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: drvctl.c,v 1.14 2011/10/19 22:13:46 dyoung Exp $ */
+/* $NetBSD: drvctl.c,v 1.15 2012/01/16 19:43:50 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2004
@@ -44,7 +44,8 @@
 					  : O_RDONLY)
 
 __dead static void usage(void);
-static void extract_property(prop_dictionary_t, const char *);
+static void extract_property(prop_dictionary_t, const char *, bool);
+static void display_object(prop_object_t, bool);
 static void list_children(int, char *, bool, bool, int);
 
 static void
@@ -208,7 +209,7 @@ main(int argc, char **argv)
 			free(xml);
 		} else {
 			for (i = 1; i < argc; i++)
-				extract_property(data_dict, argv[i]);
+				extract_property(data_dict, argv[i], nflag);
 		}
 
 		prop_object_release(results_dict);
@@ -221,9 +222,9 @@ main(int argc, char **argv)
 }
 
 static void
-extract_property(prop_dictionary_t dict, const char *prop)
+extract_property(prop_dictionary_t dict, const char *prop, bool nflag)
 {
-	char *s, *p, *cur, *ep = NULL, *xml;
+	char *s, *p, *cur, *ep = NULL;
 	prop_object_t obj;
 
 	s = strdup(prop);
@@ -236,31 +237,7 @@ extract_property(prop_dictionary_t dict,
 				exit(EXIT_FAILURE);
 		} else {
 			obj = prop_dictionary_get(dict, cur);
-			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_integer_value(obj));
-				break;
-			case PROP_TYPE_STRING:
-				printf("%s\n",
-				    prop_string_cstring_nocopy(obj));
-				break;
-			case PROP_TYPE_DICTIONARY:
-				xml = prop_dictionary_externalize(obj);
-				printf("%s", xml);
-				free(xml);
-				break;
-			default:
-				fprintf(stderr, "unhandled type %d\n",
-				    prop_object_type(obj));
-				exit(EXIT_FAILURE);
-			}
+			display_object(obj, nflag);
 		}
 	}
 
@@ -268,6 +245,43 @@ extract_property(prop_dictionary_t dict,
 }
 
 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_integer_value(obj));
+		break;
+	case PROP_TYPE_STRING:
+		printf("%s\n", prop_string_cstring_nocopy(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:
+		fprintf(stderr, "unhandled type %d\n", prop_object_type(obj));
+		exit(EXIT_FAILURE);
+	}
+}
+
+static void
 list_children(int fd, char *dvname, bool nflag, bool tflag, int depth)
 {
 	struct devlistargs laa = {.l_devname = "", .l_childname = NULL,

Reply via email to