Source-Changes-HG archive

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

[src/trunk]: src/sbin/drvctl Enhance drvctl -p processing to handle new autoc...



details:   https://anonhg.NetBSD.org/src/rev/e1e3368a973e
branches:  trunk
changeset: 772793:e1e3368a973e
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Jan 16 19:43:50 2012 +0000

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

diffstat:

 sbin/drvctl/drvctl.8 |  17 +++++++++--
 sbin/drvctl/drvctl.c |  74 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 58 insertions(+), 33 deletions(-)

diffs (173 lines):

diff -r a942d2a40045 -r e1e3368a973e sbin/drvctl/drvctl.8
--- a/sbin/drvctl/drvctl.8      Mon Jan 16 19:42:40 2012 +0000
+++ b/sbin/drvctl/drvctl.8      Mon Jan 16 19:43:50 2012 +0000
@@ -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 @@
 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 @@
 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 @@
 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.
diff -r a942d2a40045 -r e1e3368a973e sbin/drvctl/drvctl.c
--- a/sbin/drvctl/drvctl.c      Mon Jan 16 19:42:40 2012 +0000
+++ b/sbin/drvctl/drvctl.c      Mon Jan 16 19:43:50 2012 +0000
@@ -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 @@
                        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 @@
 }
 
 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 @@
                                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 @@
 }
 
 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,



Home | Main Index | Thread Index | Old Index