summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ngctl
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2005-02-09 16:17:33 +0000
committerru <ru@FreeBSD.org>2005-02-09 16:17:33 +0000
commit918851f101c3ee8695a011b9ecbf8145c9190408 (patch)
tree2cfafd9851ad267815a7dd850b33110dab92de8e /usr.sbin/ngctl
parentdda796bcd3a9f1cb5ed0c163b5dcaed61b9658d5 (diff)
downloadFreeBSD-src-918851f101c3ee8695a011b9ecbf8145c9190408.zip
FreeBSD-src-918851f101c3ee8695a011b9ecbf8145c9190408.tar.gz
- Reduce the number of netgraph messages when listing
nodes from (N + 1) to 1, where N is the number of nodes in the system. - Implement "ls -l" which runs the "show" command for each node. In collaboration with: glebius
Diffstat (limited to 'usr.sbin/ngctl')
-rw-r--r--usr.sbin/ngctl/list.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/usr.sbin/ngctl/list.c b/usr.sbin/ngctl/list.c
index e905d33..6d3cc4f 100644
--- a/usr.sbin/ngctl/list.c
+++ b/usr.sbin/ngctl/list.c
@@ -39,15 +39,19 @@
#include "ngctl.h"
+#define UNNAMED "<unnamed>"
+
static int ListCmd(int ac, char **av);
const struct ngcmd list_cmd = {
ListCmd,
- "list [-n]",
+ "list [-ln]",
"Show information about all nodes",
- "The list command shows information every node that currently"
+ "The list command shows information about every node that currently"
" exists in the netgraph system. The optional -n argument limits"
- " this list to only those nodes with a global name assignment.",
+ " this list to only those nodes with a global name assignment."
+ " The optional -l argument provides verbose output that includes"
+ " hook information as well.",
{ "ls" }
};
@@ -56,14 +60,18 @@ ListCmd(int ac, char **av)
{
struct ng_mesg *resp;
struct namelist *nlist;
+ struct nodeinfo *ninfo;
+ int list_hooks = 0;
int named_only = 0;
int ch, rtn = CMDRTN_OK;
- u_int k;
/* Get options */
optind = 1;
- while ((ch = getopt(ac, av, "n")) != EOF) {
+ while ((ch = getopt(ac, av, "ln")) != EOF) {
switch (ch) {
+ case 'l':
+ list_hooks = 1;
+ break;
case 'n':
named_only = 1;
break;
@@ -99,14 +107,30 @@ ListCmd(int ac, char **av)
nlist = (struct namelist *) resp->data;
printf("There are %d total %snodes:\n",
nlist->numnames, named_only ? "named " : "");
- for (k = 0; k < nlist->numnames; k++) {
+ ninfo = nlist->nodeinfo;
+ if (list_hooks) {
char path[NG_PATHSIZ];
- char *argv[3] = { "list", "-n", path };
+ char *argv[2] = { "show", path };
- snprintf(path, sizeof(path),
- "[%lx]:", (u_long) nlist->nodeinfo[k].id);
- if ((rtn = (*show_cmd.func)(3, argv)) != CMDRTN_OK)
- break;
+ while (nlist->numnames > 0) {
+ snprintf(path, sizeof(path),
+ "[%lx]:", (u_long)ninfo->id);
+ if ((rtn = (*show_cmd.func)(2, argv)) != CMDRTN_OK)
+ break;
+ ninfo++;
+ nlist->numnames--;
+ }
+ } else {
+ while (nlist->numnames > 0) {
+ if (!*ninfo->name)
+ snprintf(ninfo->name, sizeof(ninfo->name),
+ "%s", UNNAMED);
+ printf(" Name: %-15s Type: %-15s ID: %08x "
+ "Num hooks: %d\n",
+ ninfo->name, ninfo->type, ninfo->id, ninfo->hooks);
+ ninfo++;
+ nlist->numnames--;
+ }
}
/* Done */
OpenPOWER on IntegriCloud