Author: kib
Date: Wed Sep 25 13:28:06 2019
New Revision: 352682
URL: https://svnweb.freebsd.org/changeset/base/352682

Log:
  MFC r352486:
  sysctl: use names instead of magic numbers.

Modified:
  stable/12/lib/libc/gen/sysctlnametomib.c
  stable/12/sys/kern/kern_sysctl.c
  stable/12/sys/sys/sysctl.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libc/gen/sysctlnametomib.c
==============================================================================
--- stable/12/lib/libc/gen/sysctlnametomib.c    Wed Sep 25 13:24:31 2019        
(r352681)
+++ stable/12/lib/libc/gen/sysctlnametomib.c    Wed Sep 25 13:28:06 2019        
(r352682)
@@ -47,8 +47,8 @@ sysctlnametomib(const char *name, int *mibp, size_t *s
        int oid[2];
        int error;
 
-       oid[0] = 0;
-       oid[1] = 3;
+       oid[0] = CTL_SYSCTL;
+       oid[1] = CTL_SYSCTL_NAME2OID;
 
        *sizep *= sizeof(int);
        error = sysctl(oid, 2, mibp, sizep, name, strlen(name));

Modified: stable/12/sys/kern/kern_sysctl.c
==============================================================================
--- stable/12/sys/kern/kern_sysctl.c    Wed Sep 25 13:24:31 2019        
(r352681)
+++ stable/12/sys/kern/kern_sysctl.c    Wed Sep 25 13:28:06 2019        
(r352682)
@@ -934,13 +934,18 @@ SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_FIRST, sysctl_re
  * (be aware though, that the proper interface isn't as obvious as it
  * may seem, there are various conflicting requirements.
  *
- * {0,0}       printf the entire MIB-tree.
- * {0,1,...}   return the name of the "..." OID.
- * {0,2,...}   return the next OID.
- * {0,3}       return the OID of the name in "new"
- * {0,4,...}   return the kind & format info for the "..." OID.
- * {0,5,...}   return the description of the "..." OID.
- * {0,6,...}   return the aggregation label of the "..." OID.
+ * {CTL_SYSCTL, CTL_SYSCTL_DEBUG}              printf the entire MIB-tree.
+ * {CTL_SYSCTL, CTL_SYSCTL_NAME, ...}          return the name of the "..."
+ *                                             OID.
+ * {CTL_SYSCTL, CTL_SYSCTL_NEXT, ...}          return the next OID.
+ * {CTL_SYSCTL, CTL_SYSCTL_NAME2OID}           return the OID of the name in
+ *                                             "new"
+ * {CTL_SYSCTL, CTL_SYSCTL_OIDFMT, ...}                return the kind & 
format info
+ *                                             for the "..." OID.
+ * {CTL_SYSCTL, CTL_SYSCTL_OIDDESCR, ...}      return the description of the
+ *                                             "..." OID.
+ * {CTL_SYSCTL, CTL_SYSCTL_OIDLABEL, ...}      return the aggregation label of
+ *                                             the "..." OID.
  */
 
 #ifdef SYSCTL_DEBUG
@@ -1008,8 +1013,8 @@ sysctl_sysctl_debug(SYSCTL_HANDLER_ARGS)
        return (ENOENT);
 }
 
-SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE,
-       0, 0, sysctl_sysctl_debug, "-", "");
+SYSCTL_PROC(_sysctl, CTL_SYSCTL_DEBUG, debug, CTLTYPE_STRING | CTLFLAG_RD |
+    CTLFLAG_MPSAFE, 0, 0, sysctl_sysctl_debug, "-", "");
 #endif
 
 static int
@@ -1074,8 +1079,8 @@ sysctl_sysctl_name(SYSCTL_HANDLER_ARGS)
  * XXXRW/JA: Shouldn't return name data for nodes that we don't permit in
  * capability mode.
  */
-static SYSCTL_NODE(_sysctl, 1, name, CTLFLAG_RD | CTLFLAG_MPSAFE | 
CTLFLAG_CAPRD,
-    sysctl_sysctl_name, "");
+static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NAME, name, CTLFLAG_RD |
+    CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_name, "");
 
 static int
 sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, 
@@ -1161,8 +1166,8 @@ sysctl_sysctl_next(SYSCTL_HANDLER_ARGS)
  * XXXRW/JA: Shouldn't return next data for nodes that we don't permit in
  * capability mode.
  */
-static SYSCTL_NODE(_sysctl, 2, next, CTLFLAG_RD | CTLFLAG_MPSAFE | 
CTLFLAG_CAPRD,
-    sysctl_sysctl_next, "");
+static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NEXT, next, CTLFLAG_RD |
+    CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_next, "");
 
 static int
 name2oid(char *name, int *oid, int *len, struct sysctl_oid **oidpp)
@@ -1248,9 +1253,9 @@ sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS)
  * XXXRW/JA: Shouldn't return name2oid data for nodes that we don't permit in
  * capability mode.
  */
-SYSCTL_PROC(_sysctl, 3, name2oid,
-    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE
-    | CTLFLAG_CAPRW, 0, 0, sysctl_sysctl_name2oid, "I", "");
+SYSCTL_PROC(_sysctl, CTL_SYSCTL_NAME2OID, name2oid, CTLTYPE_INT | CTLFLAG_RW |
+    CTLFLAG_ANYBODY | CTLFLAG_MPSAFE | CTLFLAG_CAPRW, 0, 0,
+    sysctl_sysctl_name2oid, "I", "");
 
 static int
 sysctl_sysctl_oidfmt(SYSCTL_HANDLER_ARGS)
@@ -1278,8 +1283,8 @@ sysctl_sysctl_oidfmt(SYSCTL_HANDLER_ARGS)
 }
 
 
-static SYSCTL_NODE(_sysctl, 4, oidfmt, CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD,
-    sysctl_sysctl_oidfmt, "");
+static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDFMT, oidfmt, CTLFLAG_RD |
+    CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidfmt, "");
 
 static int
 sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)
@@ -1303,8 +1308,8 @@ sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)
        return (error);
 }
 
-static SYSCTL_NODE(_sysctl, 5, oiddescr, 
CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD,
-    sysctl_sysctl_oiddescr, "");
+static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDDESCR, oiddescr, CTLFLAG_RD |
+    CTLFLAG_MPSAFE|CTLFLAG_CAPRD, sysctl_sysctl_oiddescr, "");
 
 static int
 sysctl_sysctl_oidlabel(SYSCTL_HANDLER_ARGS)
@@ -1328,8 +1333,8 @@ sysctl_sysctl_oidlabel(SYSCTL_HANDLER_ARGS)
        return (error);
 }
 
-static SYSCTL_NODE(_sysctl, 6, oidlabel,
-    CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidlabel, "");
+static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDLABEL, oidlabel, CTLFLAG_RD |
+    CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidlabel, "");
 
 /*
  * Default "handler" functions.
@@ -1809,8 +1814,8 @@ kernel_sysctlbyname(struct thread *td, char *name, voi
         size_t oidlen, plen;
        int error;
 
-       oid[0] = 0;             /* sysctl internal magic */
-       oid[1] = 3;             /* name2oid */
+       oid[0] = CTL_SYSCTL;
+       oid[1] = CTL_SYSCTL_NAME2OID;
        oidlen = sizeof(oid);
 
        error = kernel_sysctl(td, oid, 2, oid, &oidlen,

Modified: stable/12/sys/sys/sysctl.h
==============================================================================
--- stable/12/sys/sys/sysctl.h  Wed Sep 25 13:24:31 2019        (r352681)
+++ stable/12/sys/sys/sysctl.h  Wed Sep 25 13:28:06 2019        (r352682)
@@ -851,7 +851,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
 /*
  * Top-level identifiers
  */
-#define        CTL_UNSPEC      0               /* unused */
+#define        CTL_SYSCTL      0               /* "magic" numbers */
 #define        CTL_KERN        1               /* "high kernel": proc, limits 
*/
 #define        CTL_VM          2               /* virtual memory */
 #define        CTL_VFS         3               /* filesystem, mount type is 
next */
@@ -861,6 +861,17 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
 #define        CTL_MACHDEP     7               /* machine dependent */
 #define        CTL_USER        8               /* user-level */
 #define        CTL_P1003_1B    9               /* POSIX 1003.1B */
+
+/*
+ * CTL_SYSCTL identifiers
+ */
+#define        CTL_SYSCTL_DEBUG        0       /* printf all nodes */
+#define        CTL_SYSCTL_NAME         1       /* string name of OID */
+#define        CTL_SYSCTL_NEXT         2       /* next OID */
+#define        CTL_SYSCTL_NAME2OID     3       /* int array of name */
+#define        CTL_SYSCTL_OIDFMT       4       /* OID's kind and format */
+#define        CTL_SYSCTL_OIDDESCR     5       /* OID's description */
+#define        CTL_SYSCTL_OIDLABEL     6       /* aggregation label */
 
 /*
  * CTL_KERN identifiers
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to