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/export.h>
13 #include <linux/uts.h>
14 #include <linux/utsname.h>
15 #include <linux/sysctl.h>
16 #include <linux/wait.h>
18 #ifdef CONFIG_PROC_SYSCTL
20 static void *get_uts(struct ctl_table
*table
)
22 char *which
= table
->data
;
23 struct uts_namespace
*uts_ns
;
25 uts_ns
= current
->nsproxy
->uts_ns
;
26 which
= (which
- (char *)&init_uts_ns
) + (char *)uts_ns
;
32 * Special case of dostring for the UTS structure. This has locks
33 * to observe. Should this be in kernel/sys.c ????
35 static int proc_do_uts_string(struct ctl_table
*table
, int write
,
36 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
38 struct ctl_table uts_table
;
40 char tmp_data
[__NEW_UTS_LEN
+ 1];
42 memcpy(&uts_table
, table
, sizeof(uts_table
));
43 uts_table
.data
= tmp_data
;
46 * Buffer the value in tmp_data so that proc_dostring() can be called
47 * without holding any locks.
48 * We also need to read the original value in the write==1 case to
49 * support partial writes.
52 memcpy(tmp_data
, get_uts(table
), sizeof(tmp_data
));
54 r
= proc_dostring(&uts_table
, write
, buffer
, lenp
, ppos
);
58 * Write back the new value.
59 * Note that, since we dropped uts_sem, the result can
60 * theoretically be incorrect if there are two parallel writes
61 * at non-zero offsets to the same sysctl.
64 memcpy(get_uts(table
), tmp_data
, sizeof(tmp_data
));
66 proc_sys_poll_notify(table
->poll
);
72 #define proc_do_uts_string NULL
75 static DEFINE_CTL_TABLE_POLL(hostname_poll
);
76 static DEFINE_CTL_TABLE_POLL(domainname_poll
);
78 static struct ctl_table uts_kern_table
[] = {
81 .data
= init_uts_ns
.name
.sysname
,
82 .maxlen
= sizeof(init_uts_ns
.name
.sysname
),
84 .proc_handler
= proc_do_uts_string
,
87 .procname
= "osrelease",
88 .data
= init_uts_ns
.name
.release
,
89 .maxlen
= sizeof(init_uts_ns
.name
.release
),
91 .proc_handler
= proc_do_uts_string
,
94 .procname
= "version",
95 .data
= init_uts_ns
.name
.version
,
96 .maxlen
= sizeof(init_uts_ns
.name
.version
),
98 .proc_handler
= proc_do_uts_string
,
101 .procname
= "hostname",
102 .data
= init_uts_ns
.name
.nodename
,
103 .maxlen
= sizeof(init_uts_ns
.name
.nodename
),
105 .proc_handler
= proc_do_uts_string
,
106 .poll
= &hostname_poll
,
109 .procname
= "domainname",
110 .data
= init_uts_ns
.name
.domainname
,
111 .maxlen
= sizeof(init_uts_ns
.name
.domainname
),
113 .proc_handler
= proc_do_uts_string
,
114 .poll
= &domainname_poll
,
119 static struct ctl_table uts_root_table
[] = {
121 .procname
= "kernel",
123 .child
= uts_kern_table
,
128 #ifdef CONFIG_PROC_SYSCTL
130 * Notify userspace about a change in a certain entry of uts_kern_table,
131 * identified by the parameter proc.
133 void uts_proc_notify(enum uts_proc proc
)
135 struct ctl_table
*table
= &uts_kern_table
[proc
];
137 proc_sys_poll_notify(table
->poll
);
141 static int __init
utsname_sysctl_init(void)
143 register_sysctl_table(uts_root_table
);
147 device_initcall(utsname_sysctl_init
);