4

Consider this 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);

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?

EDIT: More entries inside procmon, that is. For example, procmon.another_state

4

2 回答 2

2

sysctl.h中没有用于更改 sysctl 表的函数。

您必须在调用之前列出您可能需要的所有条目register_sysctl_table

如果事后确实需要更改表格,则必须unregister_sysctl_table在进行修改之前调用,然后重新注册。

于 2013-11-25T08:23:46.263 回答
1

是的,您可以,只需查看 linux 内核的驱动程序目录即可获得许多示例。本质上,您只需要多次调用 register_sysctl_table() ,对于您进行的每次调用,您都将在现有分支上创建一个分支。

此处介绍了详细信息:

https://tthtlc.wordpress.com/2016/05/26/how-to-add-new-entries-to-sysctl-with-the-same-root/

于 2016-05-26T14:54:03.527 回答