动态地添加条目sysctl相关 [英] Dynamically adding entries to sysctl
问题描述
考虑这个code:
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
)。
This will create an entry in /proc/sys
(so I could then just sysctl procmon.state=1
).
我的问题是:一旦项创建,我怎么能添加更多项
My question is: Once that entry is created, how can I add more entries?
编辑:在将procmon
更多条目,那是。例如, procmon.another_state
More entries inside procmon
, that is. For example, procmon.another_state
推荐答案
有对的 sysctl.h 。
您必须列出所有条目,你可能需要的前的调用 register_sysctl_table
。
You have to list all entries that you might need before calling register_sysctl_table
.
如果你真的需要事后更改表,你必须做你的修改之前调用 unregister_sysctl_table
,然后重新注册。
If you really need to change the table afterwards, you have to call unregister_sysctl_table
before doing your modifications, and then register it again.
这篇关于动态地添加条目sysctl相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!