add support for listing debugging variables
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 19 Apr 1993 15:15:45 +0000 (07:15 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 19 Apr 1993 15:15:45 +0000 (07:15 -0800)
SCCS-vsn: usr.sbin/sysctl/sysctl.c 5.5

usr/src/usr.sbin/sysctl/sysctl.c

index 1d29fe0..e2a6e96 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)sysctl.c   5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)sysctl.c   5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -35,6 +35,8 @@ struct ctlname kernname[] = CTL_KERN_NAMES;
 struct ctlname vmname[] = CTL_VM_NAMES;
 struct ctlname netname[] = CTL_NET_NAMES;
 struct ctlname hwname[] = CTL_HW_NAMES;
 struct ctlname vmname[] = CTL_VM_NAMES;
 struct ctlname netname[] = CTL_NET_NAMES;
 struct ctlname hwname[] = CTL_HW_NAMES;
+struct ctlname debugname[CTL_DEBUG_MAXID];
+char names[BUFSIZ];
 
 struct list {
        struct  ctlname *list;
 
 struct list {
        struct  ctlname *list;
@@ -47,7 +49,7 @@ struct list secondlevel[] = {
        { vmname, VM_MAXID },           /* CTL_VM */
        { 0, 0 },                       /* CTL_FS */
        { netname, NET_MAXID },         /* CTL_NET */
        { vmname, VM_MAXID },           /* CTL_VM */
        { 0, 0 },                       /* CTL_FS */
        { netname, NET_MAXID },         /* CTL_NET */
-       { 0, 0 },                       /* CTL_DEBUG */
+       { 0, CTL_DEBUG_MAXID },         /* CTL_DEBUG */
        { hwname, HW_MAXID },           /* CTL_HW */
        { 0, 0 },                       /* CTL_MACHDEP */
 };
        { hwname, HW_MAXID },           /* CTL_HW */
        { 0, 0 },                       /* CTL_MACHDEP */
 };
@@ -90,6 +92,7 @@ main(argc, argv)
        argv += optind;
 
        if (Aflag || aflag) {
        argv += optind;
 
        if (Aflag || aflag) {
+               debuginit();
                for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
                        listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
                exit(0);
                for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
                        listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
                exit(0);
@@ -159,6 +162,8 @@ parse(string, flags)
        if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
                return;
        mib[0] = indx;
        if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
                return;
        mib[0] = indx;
+       if (indx == CTL_DEBUG)
+               debuginit();
        lp = &secondlevel[indx];
        if (lp->list == 0) {
                fprintf(stderr, "%s: class is not implemented\n",
        lp = &secondlevel[indx];
        if (lp->list == 0) {
                fprintf(stderr, "%s: class is not implemented\n",
@@ -229,8 +234,12 @@ parse(string, flags)
                fprintf(stderr, "Use netstat to view %s information\n", string);
                return;
 
                fprintf(stderr, "Use netstat to view %s information\n", string);
                return;
 
-       case CTL_FS:
        case CTL_DEBUG:
        case CTL_DEBUG:
+               mib[2] = CTL_DEBUG_VALUE;
+               len = 3;
+               break;
+
+       case CTL_FS:
        case CTL_MACHDEP:
                break;
 
        case CTL_MACHDEP:
                break;
 
@@ -341,6 +350,29 @@ parse(string, flags)
        }
 }
 
        }
 }
 
+/*
+ * Initialize the set of debugging names
+ */
+debuginit()
+{
+       int mib[3], size, loc, i;
+
+       if (secondlevel[CTL_DEBUG].list != 0)
+               return;
+       secondlevel[CTL_DEBUG].list = debugname;
+       mib[0] = CTL_DEBUG;
+       mib[2] = CTL_DEBUG_NAME;
+       for (loc = 0, i = 0; i < CTL_DEBUG_MAXID; i++) {
+               mib[1] = i;
+               size = BUFSIZ - loc;
+               if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1)
+                       continue;
+               debugname[i].ctl_name = &names[loc];
+               debugname[i].ctl_type = CTLTYPE_INT;
+               loc += size;
+       }
+}
+
 struct ctlname inetname[] = CTL_IPPROTO_NAMES;
 struct ctlname ipname[] = IPCTL_NAMES;
 struct ctlname icmpname[] = ICMPCTL_NAMES;
 struct ctlname inetname[] = CTL_IPPROTO_NAMES;
 struct ctlname ipname[] = IPCTL_NAMES;
 struct ctlname icmpname[] = ICMPCTL_NAMES;