Skip to content

Commit 39732ac

Browse files
ebiedermLinus Torvalds
authored andcommitted
[PATCH] sysctl: move utsname sysctls to their own file
This is just a simple cleanup to keep kernel/sysctl.c from getting to crowded with special cases, and by keeping all of the utsname logic to together it makes the code a little more readable. Signed-off-by: Eric W. Biederman <[email protected]> Cc: Serge E. Hallyn <[email protected]> Cc: Herbert Poetzl <[email protected]> Cc: Kirill Korotaev <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b04c3af commit 39732ac

File tree

3 files changed

+147
-117
lines changed

3 files changed

+147
-117
lines changed

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
4747
obj-$(CONFIG_SECCOMP) += seccomp.o
4848
obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
4949
obj-$(CONFIG_RELAY) += relay.o
50+
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
5051
obj-$(CONFIG_UTS_NS) += utsname.o
5152
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
5253
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o

kernel/sysctl.c

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ static int parse_table(int __user *, int, void __user *, size_t __user *,
135135
void __user *, size_t, ctl_table *);
136136
#endif
137137

138-
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
139-
void __user *buffer, size_t *lenp, loff_t *ppos);
140-
141-
static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
142-
void __user *oldval, size_t __user *oldlenp,
143-
void __user *newval, size_t newlen);
144-
145138
#ifdef CONFIG_SYSVIPC
146139
static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
147140
void __user *oldval, size_t __user *oldlenp,
@@ -176,29 +169,6 @@ extern ctl_table inotify_table[];
176169
int sysctl_legacy_va_layout;
177170
#endif
178171

179-
180-
static void *get_uts(ctl_table *table, int write)
181-
{
182-
char *which = table->data;
183-
#ifdef CONFIG_UTS_NS
184-
struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
185-
which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
186-
#endif
187-
if (!write)
188-
down_read(&uts_sem);
189-
else
190-
down_write(&uts_sem);
191-
return which;
192-
}
193-
194-
static void put_uts(ctl_table *table, int write, void *which)
195-
{
196-
if (!write)
197-
up_read(&uts_sem);
198-
else
199-
up_write(&uts_sem);
200-
}
201-
202172
#ifdef CONFIG_SYSVIPC
203173
static void *get_ipc(ctl_table *table, int write)
204174
{
@@ -277,51 +247,6 @@ static ctl_table root_table[] = {
277247
};
278248

279249
static ctl_table kern_table[] = {
280-
{
281-
.ctl_name = KERN_OSTYPE,
282-
.procname = "ostype",
283-
.data = init_uts_ns.name.sysname,
284-
.maxlen = sizeof(init_uts_ns.name.sysname),
285-
.mode = 0444,
286-
.proc_handler = &proc_do_uts_string,
287-
.strategy = &sysctl_uts_string,
288-
},
289-
{
290-
.ctl_name = KERN_OSRELEASE,
291-
.procname = "osrelease",
292-
.data = init_uts_ns.name.release,
293-
.maxlen = sizeof(init_uts_ns.name.release),
294-
.mode = 0444,
295-
.proc_handler = &proc_do_uts_string,
296-
.strategy = &sysctl_uts_string,
297-
},
298-
{
299-
.ctl_name = KERN_VERSION,
300-
.procname = "version",
301-
.data = init_uts_ns.name.version,
302-
.maxlen = sizeof(init_uts_ns.name.version),
303-
.mode = 0444,
304-
.proc_handler = &proc_do_uts_string,
305-
.strategy = &sysctl_uts_string,
306-
},
307-
{
308-
.ctl_name = KERN_NODENAME,
309-
.procname = "hostname",
310-
.data = init_uts_ns.name.nodename,
311-
.maxlen = sizeof(init_uts_ns.name.nodename),
312-
.mode = 0644,
313-
.proc_handler = &proc_do_uts_string,
314-
.strategy = &sysctl_uts_string,
315-
},
316-
{
317-
.ctl_name = KERN_DOMAINNAME,
318-
.procname = "domainname",
319-
.data = init_uts_ns.name.domainname,
320-
.maxlen = sizeof(init_uts_ns.name.domainname),
321-
.mode = 0644,
322-
.proc_handler = &proc_do_uts_string,
323-
.strategy = &sysctl_uts_string,
324-
},
325250
{
326251
.ctl_name = KERN_PANIC,
327252
.procname = "panic",
@@ -1759,21 +1684,6 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
17591684
buffer, lenp, ppos);
17601685
}
17611686

1762-
/*
1763-
* Special case of dostring for the UTS structure. This has locks
1764-
* to observe. Should this be in kernel/sys.c ????
1765-
*/
1766-
1767-
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1768-
void __user *buffer, size_t *lenp, loff_t *ppos)
1769-
{
1770-
int r;
1771-
void *which;
1772-
which = get_uts(table, write);
1773-
r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1774-
put_uts(table, write, which);
1775-
return r;
1776-
}
17771687

17781688
static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
17791689
int *valp,
@@ -2410,12 +2320,6 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
24102320
return -ENOSYS;
24112321
}
24122322

2413-
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2414-
void __user *buffer, size_t *lenp, loff_t *ppos)
2415-
{
2416-
return -ENOSYS;
2417-
}
2418-
24192323
#ifdef CONFIG_SYSVIPC
24202324
static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
24212325
void __user *buffer, size_t *lenp, loff_t *ppos)
@@ -2645,21 +2549,6 @@ int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
26452549
}
26462550

26472551

2648-
/* The generic string strategy routine: */
2649-
static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2650-
void __user *oldval, size_t __user *oldlenp,
2651-
void __user *newval, size_t newlen)
2652-
{
2653-
struct ctl_table uts_table;
2654-
int r, write;
2655-
write = newval && newlen;
2656-
memcpy(&uts_table, table, sizeof(uts_table));
2657-
uts_table.data = get_uts(table, write);
2658-
r = sysctl_string(&uts_table, name, nlen,
2659-
oldval, oldlenp, newval, newlen);
2660-
put_uts(table, write, uts_table.data);
2661-
return r;
2662-
}
26632552

26642553
#ifdef CONFIG_SYSVIPC
26652554
/* The generic sysctl ipc data routine. */
@@ -2766,12 +2655,6 @@ int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
27662655
return -ENOSYS;
27672656
}
27682657

2769-
static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2770-
void __user *oldval, size_t __user *oldlenp,
2771-
void __user *newval, size_t newlen)
2772-
{
2773-
return -ENOSYS;
2774-
}
27752658
#ifdef CONFIG_SYSVIPC
27762659
static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
27772660
void __user *oldval, size_t __user *oldlenp,

kernel/utsname_sysctl.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright (C) 2007
3+
*
4+
* Author: Eric Biederman <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation, version 2 of the
9+
* License.
10+
*/
11+
12+
#include <linux/module.h>
13+
#include <linux/uts.h>
14+
#include <linux/utsname.h>
15+
#include <linux/version.h>
16+
#include <linux/sysctl.h>
17+
18+
static void *get_uts(ctl_table *table, int write)
19+
{
20+
char *which = table->data;
21+
#ifdef CONFIG_UTS_NS
22+
struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
23+
which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
24+
#endif
25+
if (!write)
26+
down_read(&uts_sem);
27+
else
28+
down_write(&uts_sem);
29+
return which;
30+
}
31+
32+
static void put_uts(ctl_table *table, int write, void *which)
33+
{
34+
if (!write)
35+
up_read(&uts_sem);
36+
else
37+
up_write(&uts_sem);
38+
}
39+
40+
#ifdef CONFIG_PROC_FS
41+
/*
42+
* Special case of dostring for the UTS structure. This has locks
43+
* to observe. Should this be in kernel/sys.c ????
44+
*/
45+
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
46+
void __user *buffer, size_t *lenp, loff_t *ppos)
47+
{
48+
struct ctl_table uts_table;
49+
int r;
50+
memcpy(&uts_table, table, sizeof(uts_table));
51+
uts_table.data = get_uts(table, write);
52+
r = proc_dostring(&uts_table,write,filp,buffer,lenp, ppos);
53+
put_uts(table, write, uts_table.data);
54+
return r;
55+
}
56+
#else
57+
#define proc_do_uts_string NULL
58+
#endif
59+
60+
61+
#ifdef CONFIG_SYSCTL_SYSCALL
62+
/* The generic string strategy routine: */
63+
static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
64+
void __user *oldval, size_t __user *oldlenp,
65+
void __user *newval, size_t newlen)
66+
{
67+
struct ctl_table uts_table;
68+
int r, write;
69+
write = newval && newlen;
70+
memcpy(&uts_table, table, sizeof(uts_table));
71+
uts_table.data = get_uts(table, write);
72+
r = sysctl_string(&uts_table, name, nlen,
73+
oldval, oldlenp, newval, newlen);
74+
put_uts(table, write, uts_table.data);
75+
return r;
76+
}
77+
#else
78+
#define sysctl_uts_string NULL
79+
#endif
80+
81+
static struct ctl_table uts_kern_table[] = {
82+
{
83+
.ctl_name = KERN_OSTYPE,
84+
.procname = "ostype",
85+
.data = init_uts_ns.name.sysname,
86+
.maxlen = sizeof(init_uts_ns.name.sysname),
87+
.mode = 0444,
88+
.proc_handler = proc_do_uts_string,
89+
.strategy = sysctl_uts_string,
90+
},
91+
{
92+
.ctl_name = KERN_OSRELEASE,
93+
.procname = "osrelease",
94+
.data = init_uts_ns.name.release,
95+
.maxlen = sizeof(init_uts_ns.name.release),
96+
.mode = 0444,
97+
.proc_handler = proc_do_uts_string,
98+
.strategy = sysctl_uts_string,
99+
},
100+
{
101+
.ctl_name = KERN_VERSION,
102+
.procname = "version",
103+
.data = init_uts_ns.name.version,
104+
.maxlen = sizeof(init_uts_ns.name.version),
105+
.mode = 0444,
106+
.proc_handler = proc_do_uts_string,
107+
.strategy = sysctl_uts_string,
108+
},
109+
{
110+
.ctl_name = KERN_NODENAME,
111+
.procname = "hostname",
112+
.data = init_uts_ns.name.nodename,
113+
.maxlen = sizeof(init_uts_ns.name.nodename),
114+
.mode = 0644,
115+
.proc_handler = proc_do_uts_string,
116+
.strategy = sysctl_uts_string,
117+
},
118+
{
119+
.ctl_name = KERN_DOMAINNAME,
120+
.procname = "domainname",
121+
.data = init_uts_ns.name.domainname,
122+
.maxlen = sizeof(init_uts_ns.name.domainname),
123+
.mode = 0644,
124+
.proc_handler = proc_do_uts_string,
125+
.strategy = sysctl_uts_string,
126+
},
127+
{}
128+
};
129+
130+
static struct ctl_table uts_root_table[] = {
131+
{
132+
.ctl_name = CTL_KERN,
133+
.procname = "kernel",
134+
.mode = 0555,
135+
.child = uts_kern_table,
136+
},
137+
{}
138+
};
139+
140+
static int __init utsname_sysctl_init(void)
141+
{
142+
register_sysctl_table(uts_root_table, 0);
143+
return 0;
144+
}
145+
146+
__initcall(utsname_sysctl_init);

0 commit comments

Comments
 (0)