4 * Author: Eric Biederman <ebiederm@xmision.com>
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
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>
18 static void *get_uts(ctl_table
*table
, int write
)
20 char *which
= table
->data
;
21 struct uts_namespace
*uts_ns
;
23 uts_ns
= current
->nsproxy
->uts_ns
;
24 which
= (which
- (char *)&init_uts_ns
) + (char *)uts_ns
;
33 static void put_uts(ctl_table
*table
, int write
, void *which
)
43 * Special case of dostring for the UTS structure. This has locks
44 * to observe. Should this be in kernel/sys.c ????
46 static int proc_do_uts_string(ctl_table
*table
, int write
, struct file
*filp
,
47 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
49 struct ctl_table uts_table
;
51 memcpy(&uts_table
, table
, sizeof(uts_table
));
52 uts_table
.data
= get_uts(table
, write
);
53 r
= proc_dostring(&uts_table
,write
,filp
,buffer
,lenp
, ppos
);
54 put_uts(table
, write
, uts_table
.data
);
58 #define proc_do_uts_string NULL
62 #ifdef CONFIG_SYSCTL_SYSCALL
63 /* The generic string strategy routine: */
64 static int sysctl_uts_string(ctl_table
*table
, int __user
*name
, int nlen
,
65 void __user
*oldval
, size_t __user
*oldlenp
,
66 void __user
*newval
, size_t newlen
)
68 struct ctl_table uts_table
;
70 write
= newval
&& newlen
;
71 memcpy(&uts_table
, table
, sizeof(uts_table
));
72 uts_table
.data
= get_uts(table
, write
);
73 r
= sysctl_string(&uts_table
, name
, nlen
,
74 oldval
, oldlenp
, newval
, newlen
);
75 put_uts(table
, write
, uts_table
.data
);
79 #define sysctl_uts_string NULL
82 static struct ctl_table uts_kern_table
[] = {
84 .ctl_name
= KERN_OSTYPE
,
86 .data
= init_uts_ns
.name
.sysname
,
87 .maxlen
= sizeof(init_uts_ns
.name
.sysname
),
89 .proc_handler
= proc_do_uts_string
,
90 .strategy
= sysctl_uts_string
,
93 .ctl_name
= KERN_OSRELEASE
,
94 .procname
= "osrelease",
95 .data
= init_uts_ns
.name
.release
,
96 .maxlen
= sizeof(init_uts_ns
.name
.release
),
98 .proc_handler
= proc_do_uts_string
,
99 .strategy
= sysctl_uts_string
,
102 .ctl_name
= KERN_VERSION
,
103 .procname
= "version",
104 .data
= init_uts_ns
.name
.version
,
105 .maxlen
= sizeof(init_uts_ns
.name
.version
),
107 .proc_handler
= proc_do_uts_string
,
108 .strategy
= sysctl_uts_string
,
111 .ctl_name
= KERN_NODENAME
,
112 .procname
= "hostname",
113 .data
= init_uts_ns
.name
.nodename
,
114 .maxlen
= sizeof(init_uts_ns
.name
.nodename
),
116 .proc_handler
= proc_do_uts_string
,
117 .strategy
= sysctl_uts_string
,
120 .ctl_name
= KERN_DOMAINNAME
,
121 .procname
= "domainname",
122 .data
= init_uts_ns
.name
.domainname
,
123 .maxlen
= sizeof(init_uts_ns
.name
.domainname
),
125 .proc_handler
= proc_do_uts_string
,
126 .strategy
= sysctl_uts_string
,
131 static struct ctl_table uts_root_table
[] = {
133 .ctl_name
= CTL_KERN
,
134 .procname
= "kernel",
136 .child
= uts_kern_table
,
141 static int __init
utsname_sysctl_init(void)
143 register_sysctl_table(uts_root_table
);
147 __initcall(utsname_sysctl_init
);