Skip to content

Commit de4e83b

Browse files
committed
sysctl: Register the base sysctl table like any other sysctl table.
Simplify the code by treating the base sysctl table like any other sysctl table and register it with register_sysctl_table. To ensure this table is registered early enough to avoid problems call sysctl_init from proc_sys_init. Rename sysctl_net.c:sysctl_init() to net_sysctl_init() to avoid name conflicts now that kernel/sysctl.c:sysctl_init() is no longer static. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
1 parent 0ce8974 commit de4e83b

4 files changed

Lines changed: 9 additions & 12 deletions

File tree

‎fs/proc/proc_sysctl.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,5 +468,6 @@ int __init proc_sys_init(void)
468468
proc_sys_root->proc_iops = &proc_sys_dir_operations;
469469
proc_sys_root->proc_fops = &proc_sys_dir_file_operations;
470470
proc_sys_root->nlink = 0;
471-
return 0;
471+
472+
return sysctl_init();
472473
}

‎include/linux/sysctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
10951095
void unregister_sysctl_table(struct ctl_table_header * table);
10961096
int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table);
10971097

1098+
extern int sysctl_init(void);
10981099
#else /* CONFIG_SYSCTL */
10991100
static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
11001101
{

‎kernel/sysctl.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
192192

193193
#endif
194194

195-
static struct ctl_table root_table[];
195+
static struct ctl_table root_table[1];
196196
static struct ctl_table_root sysctl_table_root;
197197
static struct ctl_table_header root_table_header = {
198198
{{.count = 1,
@@ -222,7 +222,7 @@ int sysctl_legacy_va_layout;
222222

223223
/* The default sysctl tables: */
224224

225-
static struct ctl_table root_table[] = {
225+
static struct ctl_table sysctl_base_table[] = {
226226
{
227227
.procname = "kernel",
228228
.mode = 0555,
@@ -1747,17 +1747,12 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
17471747
}
17481748
}
17491749

1750-
static __init int sysctl_init(void)
1750+
int __init sysctl_init(void)
17511751
{
1752-
sysctl_set_parent(NULL, root_table);
1753-
#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1754-
sysctl_check_table(current->nsproxy, root_table);
1755-
#endif
1752+
register_sysctl_table(sysctl_base_table);
17561753
return 0;
17571754
}
17581755

1759-
core_initcall(sysctl_init);
1760-
17611756
static struct ctl_table *is_branch_in(struct ctl_table *branch,
17621757
struct ctl_table *table)
17631758
{

‎net/sysctl_net.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static struct pernet_operations sysctl_pernet_ops = {
9090
.exit = sysctl_net_exit,
9191
};
9292

93-
static __init int sysctl_init(void)
93+
static __init int net_sysctl_init(void)
9494
{
9595
int ret;
9696
ret = register_pernet_subsys(&sysctl_pernet_ops);
@@ -102,7 +102,7 @@ static __init int sysctl_init(void)
102102
out:
103103
return ret;
104104
}
105-
subsys_initcall(sysctl_init);
105+
subsys_initcall(net_sysctl_init);
106106

107107
struct ctl_table_header *register_net_sysctl_table(struct net *net,
108108
const struct ctl_path *path, struct ctl_table *table)

0 commit comments

Comments
 (0)