Thanks for the reviews!

Marcus Glocker <mar...@nazgul.ch> writes:

> On Sat, 9 Jan 2021 22:09:06 +0100
> Marcus Glocker <mar...@nazgul.ch> wrote:
> If you could fix the switch() indentation in a separate commit (as you
> already mentioned in one of your previous e-mails), that would be nice.

How's this instead? OK?

Tested with the usual diff of before/after sysctl outputs and a random
sysctl -w poke.

Subject: [PATCH] Split hierarchical calls into kern_sysctl_dirs

Removed a rash of +/-1 and made both functions shorter and more focused.
---
 sys/kern/kern_sysctl.c | 86 ++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 41 deletions(-)

diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c
index 7b164d3d32a..383b2a7c074 100644
--- sys/kern/kern_sysctl.c
+++ sys/kern/kern_sysctl.c
@@ -352,106 +352,110 @@ const struct sysctl_bounded_args kern_vars[] = {
 #endif
 };
 
-/*
- * kernel related system variables.
- */
 int
-kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
-    size_t newlen, struct proc *p)
+kern_sysctl_dirs(int top_name, int *name, u_int namelen,
+    void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct proc *p)
 {
-       int error, level, inthostid, stackgap;
-       dev_t dev;
-       extern int pool_debug;
-
-       /* dispatch the non-terminal nodes first */
-       if (namelen != 1) {
-               switch (name[0]) {
+       switch (top_name) {
 #ifndef SMALL_KERNEL
        case KERN_PROC:
-               return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp));
+               return (sysctl_doproc(name, namelen, oldp, oldlenp));
        case KERN_PROC_ARGS:
-               return (sysctl_proc_args(name + 1, namelen - 1, oldp, oldlenp,
-                    p));
+               return (sysctl_proc_args(name, namelen, oldp, oldlenp, p));
        case KERN_PROC_CWD:
-               return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp,
-                    p));
+               return (sysctl_proc_cwd(name, namelen, oldp, oldlenp, p));
        case KERN_PROC_NOBROADCASTKILL:
-               return (sysctl_proc_nobroadcastkill(name + 1, namelen - 1,
+               return (sysctl_proc_nobroadcastkill(name, namelen,
                     newp, newlen, oldp, oldlenp, p));
        case KERN_PROC_VMMAP:
-               return (sysctl_proc_vmmap(name + 1, namelen - 1, oldp, oldlenp,
-                    p));
+               return (sysctl_proc_vmmap(name, namelen, oldp, oldlenp, p));
        case KERN_FILE:
-               return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p));
+               return (sysctl_file(name, namelen, oldp, oldlenp, p));
 #endif
 #if defined(GPROF) || defined(DDBPROF)
        case KERN_PROF:
-               return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_doprof(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
        case KERN_MALLOCSTATS:
-               return (sysctl_malloc(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_malloc(name, namelen, oldp, oldlenp,
                    newp, newlen, p));
        case KERN_TTY:
-               return (sysctl_tty(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_tty(name, namelen, oldp, oldlenp,
                    newp, newlen));
        case KERN_POOL:
-               return (sysctl_dopool(name + 1, namelen - 1, oldp, oldlenp));
+               return (sysctl_dopool(name, namelen, oldp, oldlenp));
 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
        case KERN_SYSVIPC_INFO:
-               return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp));
+               return (sysctl_sysvipc(name, namelen, oldp, oldlenp));
 #endif
 #ifdef SYSVSEM
        case KERN_SEMINFO:
-               return (sysctl_sysvsem(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_sysvsem(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
 #ifdef SYSVSHM
        case KERN_SHMINFO:
-               return (sysctl_sysvshm(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_sysvshm(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
 #ifndef SMALL_KERNEL
        case KERN_INTRCNT:
-               return (sysctl_intrcnt(name + 1, namelen - 1, oldp, oldlenp));
+               return (sysctl_intrcnt(name, namelen, oldp, oldlenp));
        case KERN_WATCHDOG:
-               return (sysctl_wdog(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_wdog(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
 #ifndef SMALL_KERNEL
        case KERN_EVCOUNT:
-               return (evcount_sysctl(name + 1, namelen - 1, oldp, oldlenp,
+               return (evcount_sysctl(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
        case KERN_TIMECOUNTER:
-               return (sysctl_tc(name + 1, namelen - 1, oldp, oldlenp,
-                   newp, newlen));
+               return (sysctl_tc(name, namelen, oldp, oldlenp, newp, newlen));
        case KERN_CPTIME2:
-               return (sysctl_cptime2(name + 1, namelen -1, oldp, oldlenp,
+               return (sysctl_cptime2(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #ifdef WITNESS
        case KERN_WITNESSWATCH:
                return witness_sysctl_watch(oldp, oldlenp, newp, newlen);
        case KERN_WITNESS:
-               return witness_sysctl(name + 1, namelen - 1, oldp, oldlenp,
+               return witness_sysctl(name, namelen, oldp, oldlenp,
                    newp, newlen);
 #endif
 #if NAUDIO > 0
        case KERN_AUDIO:
-               return (sysctl_audio(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_audio(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
 #if NVIDEO > 0
        case KERN_VIDEO:
-               return (sysctl_video(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_video(name, namelen, oldp, oldlenp,
                    newp, newlen));
 #endif
        case KERN_CPUSTATS:
-               return (sysctl_cpustats(name + 1, namelen - 1, oldp, oldlenp,
+               return (sysctl_cpustats(name, namelen, oldp, oldlenp,
                    newp, newlen));
-               default:
-                       return (ENOTDIR);       /* overloaded */
-               }
+       default:
+               return (ENOTDIR);       /* overloaded */
+       }
+}
+
+/*
+ * kernel related system variables.
+ */
+int
+kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
+    size_t newlen, struct proc *p)
+{
+       int error, level, inthostid, stackgap;
+       dev_t dev;
+       extern int pool_debug;
+
+       /* dispatch the non-terminal nodes first */
+       if (namelen != 1) {
+               return kern_sysctl_dirs(name[0], name + 1, namelen - 1,
+                   oldp, oldlenp, newp, newlen, p);
        }
 
        switch (name[0]) {
-- 
2.29.2

Reply via email to