2013-11-23 10 views
4

이 코드를 고려 sysctl을합니다 :동적으로 추가 항목은

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

+0

될 수'register_sysctl_paths' 여기에 도움이? –

+0

나는'proc_create_data()'를 볼 것입니다. –

+0

사실,'''register_sysctl_paths'''가 도움이 될 수 있습니다. 나는 그것을 볼 것이다, 고마워! 다른면에서는,''proc_create_data''가 너무 최근 (3.10+ 만)입니다. – alexandernst

답변

2

sysctl.h에서 sysctl 테이블을 변경하는 기능은 없습니다.

전에을 호출하기 전에 register_sysctl_table으로 전화해야하는 모든 항목을 나열해야합니다.

나중에 테이블을 변경해야하는 경우 수정하기 전에 unregister_sysctl_table으로 전화를 걸어 다시 등록해야합니다.