Hey folks,

at startup all arm machines show a warning:

total memory = 512 MB
avail memory = 495 MB
sysctl_createv: sysctl_create(machine_arch) returned 17
timecounter: Timecounters tick every 10.000 msec


This is because sys/arach/arm/arm32/arm32_machdep.c creates the 
hw.machine_arch sysctl value first (overriding the generic one).
(Slightly) later kern/sysctl_init_base.c tries to create the same (but
different) value and (verbosly) fails with EEXIST.

Easy way out: use the sysctl_createv() "cflags" argument to pass in
an option telling it this is ok, and make it silently fail.

The patch attached does that.

Comments?

Martin
Index: sys/sys/sysctl.h
===================================================================
RCS file: /cvsroot/src/sys/sys/sysctl.h,v
retrieving revision 1.225
diff -u -p -r1.225 sysctl.h
--- sys/sys/sysctl.h    8 Sep 2017 10:53:55 -0000       1.225
+++ sys/sys/sysctl.h    19 Oct 2017 10:20:03 -0000
@@ -164,6 +164,11 @@ struct ctlname {
 #define CTL_DESCRIBE   (-7)            /* get node descriptions */
 
 /*
+ * cflag values for sysctl_createv()
+ */
+#define        CREATEFLAG_MAYEXIST     1
+
+/*
  * Top-level identifiers
  */
 #define        CTL_UNSPEC      0               /* unused */
Index: sys/kern/init_sysctl_base.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl_base.c,v
retrieving revision 1.7
diff -u -p -r1.7 init_sysctl_base.c
--- sys/kern/init_sysctl_base.c 25 Aug 2015 14:52:31 -0000      1.7
+++ sys/kern/init_sysctl_base.c 19 Oct 2017 10:20:03 -0000
@@ -201,7 +201,7 @@ SYSCTL_SETUP(sysctl_hwbase_setup, "sysct
                       SYSCTL_DESCR("Machine class"),
                       NULL, 0, machine, 0,
                       CTL_HW, HW_MACHINE, CTL_EOL);
-       sysctl_createv(clog, 0, NULL, NULL,
+       sysctl_createv(clog, CREATEFLAG_MAYEXIST, NULL, NULL,
                       CTLFLAG_PERMANENT,
                       CTLTYPE_STRING, "machine_arch",
                       SYSCTL_DESCR("Machine CPU class"),
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.259
diff -u -p -r1.259 kern_sysctl.c
--- sys/kern/kern_sysctl.c      25 Apr 2017 22:07:10 -0000      1.259
+++ sys/kern/kern_sysctl.c      19 Oct 2017 10:20:04 -0000
@@ -1967,7 +1967,7 @@ sysctl_createv(struct sysctllog **log, i
        root = rnode ? *rnode : NULL;
        if (cnode != NULL)
                *cnode = NULL;
-       if (cflags != 0)
+       if ((cflags & ~CREATEFLAG_MAYEXIST) != 0)
                return (EINVAL);
 
        /*
@@ -2181,12 +2181,14 @@ sysctl_createv(struct sysctllog **log, i
        sysctl_unlock();
 
        if (error != 0) {
-               printf("sysctl_createv: sysctl_create(%s) returned %d\n",
-                      nnode.sysctl_name, error);
+               if (error != EEXIST || (cflags&CREATEFLAG_MAYEXIST) == 0) {
+                       printf("sysctl_createv: sysctl_create(%s) "
+                           "returned %d\n", nnode.sysctl_name, error);
 #if 0
-               if (error != ENOENT)
-                       sysctl_dump(&onode);
+                       if (error != ENOENT)
+                               sysctl_dump(&onode);
 #endif
+               }
        }
 
        return (error);
Index: share/man/man9/sysctl.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/sysctl.9,v
retrieving revision 1.20
diff -u -p -r1.20 sysctl.9
--- share/man/man9/sysctl.9     3 Jul 2017 21:28:48 -0000       1.20
+++ share/man/man9/sysctl.9     19 Oct 2017 10:20:04 -0000
@@ -330,7 +330,22 @@ keeping on the caller's part.
 .Pp
 The
 .Fa cflags
-argument is currently unused and must be zero.
+argument controlls the creation operation in case of already existing nodes.
+It must be either
+.Dv 0
+or
+.Dv CREATEFLAG_MAYEXIST .
+The flag
+.Dv CREATEFLAG_MAYEXIST
+allows silently skipping already existing, but different nodes.
+This is for example usefull for machine dependend parts overriding
+sysctl values usually provided by the machine independ part of the
+kernel.
+Creation of exactly the same node is always silently allowed, so
+different parts of the kernel (or different modules) can create the
+same base tree and add their own subtree independent of initialization
+order.
+.Pp
 The
 .Fa rnode
 argument must either be

Reply via email to