Problem adding new SYSCTL

I'm trying to add two sysctls using the following peice of code:
C:
static unsigned int inform = 0;
static struct sysctl_ctx_list inform_sctl_ctx;

static int inform_oid_handler(SYSCTL_HANDLER_ARGS)
{
        //DO STH
        return (0);
}

static void inform_sysctls_create()
{
        struct sysctl_oid *oidp;
        struct sysctl_oid_list *child;

        sysctl_ctx_init(&inform_sctl_ctx);

        oidp = SYSCTL_ADD_NODE(&inform_sctl_ctx, SYSCTL_STATIC_CHILDREN(), OID_AUTO, "zeone", CTLFLAG_RW, 0, "some desc");

        child = SYSCTL_CHILDREN(oidp);

        SYSCTL_ADD_UINT(&inform_sctl_ctx, child, OID_AUTO, "smhf-var", CTLFLAG_RW, &inform, 0, "new leaf");
        SYSCTL_ADD_PROC(&inform_sctl_ctx, child, OID_AUTO, "smhf-proc", CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, wp_inform_oid_handler, "IU", "some desc")
}

But only "smhf-var" is registered!
smhf@devsys# sysctl -a | grep zeone
zeone.smhf-var: 0


What is the problem?
 
j4ck by any chance - did you resolve what was the cause of this behavior?

I would be glad to know too - I run into something that looks like the same problem with SYSCTL_INT

Codebase is FreeBSD11.1

Code:
****
 * Attempt on implementing own sycstl
 ****/

#include<sys/cdefs.h>
#include<sys/param.h>
#include<sys/kernel.h>
#include<sys/systm.h>
#include<sys/types.h>`
#include<sys/sysctl.h>

int thats_my_stat_var=1; /*it won't work also when declared as static int*/
int thats_my_stat_var2=2;


SYSCTL_DECL(_user);  //I tried with this and without this, it's unrolls to an extern anyway
SYSCTL_INT(_user,OID_AUTO, thats_my_stat_var,CTLFLAG_RW|CTLFLAG_ANYBODY,&thats_my_stat_var,1,"Static one");
SYSCTL_INT(_user,OID_AUTO, thats_my_stat_var2,CTLFLAG_RW|CTLFLAG_ANYBODY,&thats_my_stat_var2,2,"Static two");


I added it as a file kern/subr_examplectl.c to file list sys/conf/files, it is placed like this - 3 lines before and 3 lines after included, to give you an outlook on where I put that
Code:
kern/vfs_subr.c            standard
kern/vfs_syscalls.c        standard
kern/vfs_vnops.c        standard
kern/subr_examplectl.c        standard


#


It does not show new variables in the list but I can display it when I specify the name of sysctl variable - but it has no value, and why I'm trying to set a value there is just an error


$sysctl user.thats_my_stat_var #jes nothing is displayed as result of this command
$sysctl -d user.thats_my_stat_var #this one prints out description
user.thats_my_stat_var: Static one
$ sysctl user.thats_my_stat_var2=11
sysctl: user.thats_my_stat_var2=11: Operation not permitted


Secure level seems to not be the issue here:

$sysctl kern.securelevel
kern.securelevel: -1


What is missing here? I cannot grasp what's the matter. Is any export macro missing? Or I didn't import some specific header or maybe, or I have to add that file somewhere else too?
 
Seems like something is not stated openly enough in sources/manual/books and other manuals or was changed quiet recently. All sources I have access to are silent about any additional requirements for sysctls to be accesible. No root and no normal user is able to load their values or set/change them. But maybe I'm missing something. No idea.
 
Back
Top