aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-02-14 03:33:58 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-14 11:09:58 -0500
commit39732acd968a007036ff3c504f1e6748024ef548 (patch)
tree91d3ecdd8579559daa6b9d4b25eb688d1bb909a8 /kernel
parentb04c3afb2b6e2f902b41bb62b73684d92d7e6c34 (diff)
[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 <ebiederm@xmission.com> Cc: Serge E. Hallyn <serue@us.ibm.com> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Kirill Korotaev <dev@sw.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/sysctl.c117
-rw-r--r--kernel/utsname_sysctl.c146
3 files changed, 147 insertions, 117 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 14f4d45e0ae9..ac6b27abb1ad 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
47obj-$(CONFIG_SECCOMP) += seccomp.o 47obj-$(CONFIG_SECCOMP) += seccomp.o
48obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o 48obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
49obj-$(CONFIG_RELAY) += relay.o 49obj-$(CONFIG_RELAY) += relay.o
50obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
50obj-$(CONFIG_UTS_NS) += utsname.o 51obj-$(CONFIG_UTS_NS) += utsname.o
51obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o 52obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
52obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o 53obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ba4b0c16d6a..eff1d36c0687 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -135,13 +135,6 @@ static int parse_table(int __user *, int, void __user *, size_t __user *,
135 void __user *, size_t, ctl_table *); 135 void __user *, size_t, ctl_table *);
136#endif 136#endif
137 137
138static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
140
141static 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
145#ifdef CONFIG_SYSVIPC 138#ifdef CONFIG_SYSVIPC
146static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen, 139static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
147 void __user *oldval, size_t __user *oldlenp, 140 void __user *oldval, size_t __user *oldlenp,
@@ -176,29 +169,6 @@ extern ctl_table inotify_table[];
176int sysctl_legacy_va_layout; 169int sysctl_legacy_va_layout;
177#endif 170#endif
178 171
179
180static 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
194static 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
202#ifdef CONFIG_SYSVIPC 172#ifdef CONFIG_SYSVIPC
203static void *get_ipc(ctl_table *table, int write) 173static void *get_ipc(ctl_table *table, int write)
204{ 174{
@@ -278,51 +248,6 @@ static ctl_table root_table[] = {
278 248
279static ctl_table kern_table[] = { 249static ctl_table kern_table[] = {
280 { 250 {
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 },
325 {
326 .ctl_name = KERN_PANIC, 251 .ctl_name = KERN_PANIC,
327 .procname = "panic", 252 .procname = "panic",
328 .data = &panic_timeout, 253 .data = &panic_timeout,
@@ -1759,21 +1684,6 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
1759 buffer, lenp, ppos); 1684 buffer, lenp, ppos);
1760} 1685}
1761 1686
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
1767static 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}
1777 1687
1778static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 1688static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1779 int *valp, 1689 int *valp,
@@ -2410,12 +2320,6 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
2410 return -ENOSYS; 2320 return -ENOSYS;
2411} 2321}
2412 2322
2413static 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
2419#ifdef CONFIG_SYSVIPC 2323#ifdef CONFIG_SYSVIPC
2420static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp, 2324static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2421 void __user *buffer, size_t *lenp, loff_t *ppos) 2325 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,
2645} 2549}
2646 2550
2647 2551
2648/* The generic string strategy routine: */
2649static 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}
2663 2552
2664#ifdef CONFIG_SYSVIPC 2553#ifdef CONFIG_SYSVIPC
2665/* The generic sysctl ipc data routine. */ 2554/* The generic sysctl ipc data routine. */
@@ -2766,12 +2655,6 @@ int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2766 return -ENOSYS; 2655 return -ENOSYS;
2767} 2656}
2768 2657
2769static 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}
2775#ifdef CONFIG_SYSVIPC 2658#ifdef CONFIG_SYSVIPC
2776static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen, 2659static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2777 void __user *oldval, size_t __user *oldlenp, 2660 void __user *oldval, size_t __user *oldlenp,
diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
new file mode 100644
index 000000000000..324aa1341b5f
--- /dev/null
+++ b/kernel/utsname_sysctl.c
@@ -0,0 +1,146 @@
1/*
2 * Copyright (C) 2007
3 *
4 * Author: Eric Biederman <ebiederm@xmision.com>
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
18static 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
32static 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 */
45static 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: */
63static 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
81static 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
130static 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
140static 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);