请考虑以下代码:
int procmon_state = 0;
static struct ctl_table_header *procmon_table_header;
static ctl_table state_table[] = {
{
.procname = "state", .mode = 0666,
.proc_handler = &proc_dointvec_minmax,
.data = &procmon_state, .maxlen = sizeof(int),
.extra1 = "\x00\x00\x00\x00" /*0*/, .extra2 = "\x01\x00\x00\x00" /*1*/
},
{ 0 }
};
static ctl_table procmon_table[] = {
{
.procname = "procmon", .mode = 0555,
.child = state_table
},
{ 0 }
};
procmon_table_header = register_sysctl_table(procmon_table);这将在/proc/sys中创建一个条目(因此我可以只使用sysctl procmon.state=1)。
我的问题是:一旦创建了该条目,如何添加更多的条目?
编辑:procmon中的更多条目,也就是说。例如,procmon.another_state
发布于 2013-11-25 08:23:46
在sysctl.h中没有更改sysctl表的函数。
在调用register_sysctl_table之前,您必须列出可能需要的所有条目。
如果以后确实需要更改表,则必须在进行修改之前调用unregister_sysctl_table,然后再次注册它。
发布于 2016-05-26 14:54:03
是的,可以,只需查看linux内核的驱动程序目录中的许多示例即可。本质上,您只需要多次调用register_sysctl_table(),对于每个调用,您将从现有分支创建一个分支。
详情如下:
https://tthtlc.wordpress.com/2016/05/26/how-to-add-new-entries-to-sysctl-with-the-same-root/
https://stackoverflow.com/questions/20164041
复制相似问题