Blame view
kernel/utsname_sysctl.c
3.25 KB
b886d83c5 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
39732acd9 [PATCH] sysctl: m... |
2 3 4 5 |
/* * Copyright (C) 2007 * * Author: Eric Biederman <ebiederm@xmision.com> |
39732acd9 [PATCH] sysctl: m... |
6 |
*/ |
9984de1a5 kernel: Map most ... |
7 |
#include <linux/export.h> |
39732acd9 [PATCH] sysctl: m... |
8 9 |
#include <linux/uts.h> #include <linux/utsname.h> |
39732acd9 [PATCH] sysctl: m... |
10 |
#include <linux/sysctl.h> |
f1ecf0685 sysctl: add suppo... |
11 |
#include <linux/wait.h> |
cd9c513be sched/headers: Re... |
12 |
#include <linux/rwsem.h> |
39732acd9 [PATCH] sysctl: m... |
13 |
|
cd89f46b5 kernel/utsname_sy... |
14 |
#ifdef CONFIG_PROC_SYSCTL |
42a0cc347 sys: don't hold u... |
15 |
static void *get_uts(struct ctl_table *table) |
39732acd9 [PATCH] sysctl: m... |
16 17 |
{ char *which = table->data; |
32df81cbd Isolate the UTS n... |
18 19 20 21 |
struct uts_namespace *uts_ns; uts_ns = current->nsproxy->uts_ns; which = (which - (char *)&init_uts_ns) + (char *)uts_ns; |
7d69a1f4a remove CONFIG_UTS... |
22 |
|
39732acd9 [PATCH] sysctl: m... |
23 24 |
return which; } |
39732acd9 [PATCH] sysctl: m... |
25 26 27 28 |
/* * Special case of dostring for the UTS structure. This has locks * to observe. Should this be in kernel/sys.c ???? */ |
6f8fd1d77 sysctl: convert u... |
29 |
static int proc_do_uts_string(struct ctl_table *table, int write, |
39732acd9 [PATCH] sysctl: m... |
30 31 32 33 |
void __user *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table uts_table; int r; |
42a0cc347 sys: don't hold u... |
34 |
char tmp_data[__NEW_UTS_LEN + 1]; |
39732acd9 [PATCH] sysctl: m... |
35 |
memcpy(&uts_table, table, sizeof(uts_table)); |
42a0cc347 sys: don't hold u... |
36 37 38 39 40 41 42 43 44 45 46 |
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... |
47 |
r = proc_dostring(&uts_table, write, buffer, lenp, ppos); |
f1ecf0685 sysctl: add suppo... |
48 |
|
42a0cc347 sys: don't hold u... |
49 50 51 52 53 54 55 56 57 58 |
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... |
59 |
proc_sys_poll_notify(table->poll); |
42a0cc347 sys: don't hold u... |
60 |
} |
f1ecf0685 sysctl: add suppo... |
61 |
|
39732acd9 [PATCH] sysctl: m... |
62 63 64 65 66 |
return r; } #else #define proc_do_uts_string NULL #endif |
f1ecf0685 sysctl: add suppo... |
67 68 |
static DEFINE_CTL_TABLE_POLL(hostname_poll); static DEFINE_CTL_TABLE_POLL(domainname_poll); |
39732acd9 [PATCH] sysctl: m... |
69 70 |
static struct ctl_table uts_kern_table[] = { { |
39732acd9 [PATCH] sysctl: m... |
71 72 73 74 75 |
.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... |
76 77 |
}, { |
39732acd9 [PATCH] sysctl: m... |
78 79 80 81 82 |
.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... |
83 84 |
}, { |
39732acd9 [PATCH] sysctl: m... |
85 86 87 88 89 |
.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... |
90 91 |
}, { |
39732acd9 [PATCH] sysctl: m... |
92 93 94 95 96 |
.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... |
97 |
.poll = &hostname_poll, |
39732acd9 [PATCH] sysctl: m... |
98 99 |
}, { |
39732acd9 [PATCH] sysctl: m... |
100 101 102 103 104 |
.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... |
105 |
.poll = &domainname_poll, |
39732acd9 [PATCH] sysctl: m... |
106 107 108 109 110 111 |
}, {} }; static struct ctl_table uts_root_table[] = { { |
39732acd9 [PATCH] sysctl: m... |
112 113 114 115 116 117 |
.procname = "kernel", .mode = 0555, .child = uts_kern_table, }, {} }; |
f1ecf0685 sysctl: add suppo... |
118 119 120 121 122 123 124 125 126 127 128 129 |
#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... |
130 131 |
static int __init utsname_sysctl_init(void) { |
0b4d41471 [PATCH] sysctl: r... |
132 |
register_sysctl_table(uts_root_table); |
39732acd9 [PATCH] sysctl: m... |
133 134 |
return 0; } |
95583e4ab kernel/utsname_sy... |
135 |
device_initcall(utsname_sysctl_init); |