Blame view
kernel/utsname_sysctl.c
3.41 KB
39732acd9 [PATCH] sysctl: m... |
1 2 3 4 5 6 7 8 9 10 |
/* * Copyright (C) 2007 * * Author: Eric Biederman <ebiederm@xmision.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2 of the * License. */ |
9984de1a5 kernel: Map most ... |
11 |
#include <linux/export.h> |
39732acd9 [PATCH] sysctl: m... |
12 13 |
#include <linux/uts.h> #include <linux/utsname.h> |
39732acd9 [PATCH] sysctl: m... |
14 |
#include <linux/sysctl.h> |
f1ecf0685 sysctl: add suppo... |
15 |
#include <linux/wait.h> |
cd9c513be sched/headers: Re... |
16 |
#include <linux/rwsem.h> |
39732acd9 [PATCH] sysctl: m... |
17 |
|
cd89f46b5 kernel/utsname_sy... |
18 |
#ifdef CONFIG_PROC_SYSCTL |
b692c405a sys: don't hold u... |
19 |
static void *get_uts(struct ctl_table *table) |
39732acd9 [PATCH] sysctl: m... |
20 21 |
{ char *which = table->data; |
32df81cbd Isolate the UTS n... |
22 23 24 25 |
struct uts_namespace *uts_ns; uts_ns = current->nsproxy->uts_ns; which = (which - (char *)&init_uts_ns) + (char *)uts_ns; |
7d69a1f4a remove CONFIG_UTS... |
26 |
|
39732acd9 [PATCH] sysctl: m... |
27 28 |
return which; } |
39732acd9 [PATCH] sysctl: m... |
29 30 31 32 |
/* * Special case of dostring for the UTS structure. This has locks * to observe. Should this be in kernel/sys.c ???? */ |
6f8fd1d77 sysctl: convert u... |
33 |
static int proc_do_uts_string(struct ctl_table *table, int write, |
39732acd9 [PATCH] sysctl: m... |
34 35 36 37 |
void __user *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table uts_table; int r; |
b692c405a sys: don't hold u... |
38 |
char tmp_data[__NEW_UTS_LEN + 1]; |
39732acd9 [PATCH] sysctl: m... |
39 |
memcpy(&uts_table, table, sizeof(uts_table)); |
b692c405a sys: don't hold u... |
40 41 42 43 44 45 46 47 48 49 50 |
uts_table.data = tmp_data; /* * Buffer the value in tmp_data so that proc_dostring() can be called * without holding any locks. * We also need to read the original value in the write==1 case to * support partial writes. */ down_read(&uts_sem); memcpy(tmp_data, get_uts(table), sizeof(tmp_data)); up_read(&uts_sem); |
95583e4ab kernel/utsname_sy... |
51 |
r = proc_dostring(&uts_table, write, buffer, lenp, ppos); |
f1ecf0685 sysctl: add suppo... |
52 |
|
b692c405a sys: don't hold u... |
53 54 55 56 57 58 59 60 61 62 |
if (write) { /* * Write back the new value. * Note that, since we dropped uts_sem, the result can * theoretically be incorrect if there are two parallel writes * at non-zero offsets to the same sysctl. */ down_write(&uts_sem); memcpy(get_uts(table), tmp_data, sizeof(tmp_data)); up_write(&uts_sem); |
f1ecf0685 sysctl: add suppo... |
63 |
proc_sys_poll_notify(table->poll); |
b692c405a sys: don't hold u... |
64 |
} |
f1ecf0685 sysctl: add suppo... |
65 |
|
39732acd9 [PATCH] sysctl: m... |
66 67 68 69 70 |
return r; } #else #define proc_do_uts_string NULL #endif |
f1ecf0685 sysctl: add suppo... |
71 72 |
static DEFINE_CTL_TABLE_POLL(hostname_poll); static DEFINE_CTL_TABLE_POLL(domainname_poll); |
39732acd9 [PATCH] sysctl: m... |
73 74 |
static struct ctl_table uts_kern_table[] = { { |
39732acd9 [PATCH] sysctl: m... |
75 76 77 78 79 |
.procname = "ostype", .data = init_uts_ns.name.sysname, .maxlen = sizeof(init_uts_ns.name.sysname), .mode = 0444, .proc_handler = proc_do_uts_string, |
39732acd9 [PATCH] sysctl: m... |
80 81 |
}, { |
39732acd9 [PATCH] sysctl: m... |
82 83 84 85 86 |
.procname = "osrelease", .data = init_uts_ns.name.release, .maxlen = sizeof(init_uts_ns.name.release), .mode = 0444, .proc_handler = proc_do_uts_string, |
39732acd9 [PATCH] sysctl: m... |
87 88 |
}, { |
39732acd9 [PATCH] sysctl: m... |
89 90 91 92 93 |
.procname = "version", .data = init_uts_ns.name.version, .maxlen = sizeof(init_uts_ns.name.version), .mode = 0444, .proc_handler = proc_do_uts_string, |
39732acd9 [PATCH] sysctl: m... |
94 95 |
}, { |
39732acd9 [PATCH] sysctl: m... |
96 97 98 99 100 |
.procname = "hostname", .data = init_uts_ns.name.nodename, .maxlen = sizeof(init_uts_ns.name.nodename), .mode = 0644, .proc_handler = proc_do_uts_string, |
f1ecf0685 sysctl: add suppo... |
101 |
.poll = &hostname_poll, |
39732acd9 [PATCH] sysctl: m... |
102 103 |
}, { |
39732acd9 [PATCH] sysctl: m... |
104 105 106 107 108 |
.procname = "domainname", .data = init_uts_ns.name.domainname, .maxlen = sizeof(init_uts_ns.name.domainname), .mode = 0644, .proc_handler = proc_do_uts_string, |
f1ecf0685 sysctl: add suppo... |
109 |
.poll = &domainname_poll, |
39732acd9 [PATCH] sysctl: m... |
110 111 112 113 114 115 |
}, {} }; static struct ctl_table uts_root_table[] = { { |
39732acd9 [PATCH] sysctl: m... |
116 117 118 119 120 121 |
.procname = "kernel", .mode = 0555, .child = uts_kern_table, }, {} }; |
f1ecf0685 sysctl: add suppo... |
122 123 124 125 126 127 128 129 130 131 132 133 |
#ifdef CONFIG_PROC_SYSCTL /* * Notify userspace about a change in a certain entry of uts_kern_table, * identified by the parameter proc. */ void uts_proc_notify(enum uts_proc proc) { struct ctl_table *table = &uts_kern_table[proc]; proc_sys_poll_notify(table->poll); } #endif |
39732acd9 [PATCH] sysctl: m... |
134 135 |
static int __init utsname_sysctl_init(void) { |
0b4d41471 [PATCH] sysctl: r... |
136 |
register_sysctl_table(uts_root_table); |
39732acd9 [PATCH] sysctl: m... |
137 138 |
return 0; } |
95583e4ab kernel/utsname_sy... |
139 |
device_initcall(utsname_sysctl_init); |