Blame view

kernel/utsname_sysctl.c 3.01 KB
39732acd9   Eric W. Biederman   [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   Paul Gortmaker   kernel: Map most ...
11
  #include <linux/export.h>
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
12
13
  #include <linux/uts.h>
  #include <linux/utsname.h>
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
14
  #include <linux/sysctl.h>
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
15
  #include <linux/wait.h>
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
16

cd89f46b5   Yuanhan Liu   kernel/utsname_sy...
17
  #ifdef CONFIG_PROC_SYSCTL
6f8fd1d77   Joe Perches   sysctl: convert u...
18
  static void *get_uts(struct ctl_table *table, int write)
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
19
20
  {
  	char *which = table->data;
32df81cbd   Pavel Emelyanov   Isolate the UTS n...
21
22
23
24
  	struct uts_namespace *uts_ns;
  
  	uts_ns = current->nsproxy->uts_ns;
  	which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
7d69a1f4a   Cedric Le Goater   remove CONFIG_UTS...
25

39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
26
27
28
29
30
31
  	if (!write)
  		down_read(&uts_sem);
  	else
  		down_write(&uts_sem);
  	return which;
  }
6f8fd1d77   Joe Perches   sysctl: convert u...
32
  static void put_uts(struct ctl_table *table, int write, void *which)
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
33
34
35
36
37
38
  {
  	if (!write)
  		up_read(&uts_sem);
  	else
  		up_write(&uts_sem);
  }
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
39
40
41
42
  /*
   *	Special case of dostring for the UTS structure. This has locks
   *	to observe. Should this be in kernel/sys.c ????
   */
6f8fd1d77   Joe Perches   sysctl: convert u...
43
  static int proc_do_uts_string(struct ctl_table *table, int write,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
44
45
46
47
48
49
  		  void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct ctl_table uts_table;
  	int r;
  	memcpy(&uts_table, table, sizeof(uts_table));
  	uts_table.data = get_uts(table, write);
95583e4ab   Fabian Frederick   kernel/utsname_sy...
50
  	r = proc_dostring(&uts_table, write, buffer, lenp, ppos);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
51
  	put_uts(table, write, uts_table.data);
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
52
53
54
  
  	if (write)
  		proc_sys_poll_notify(table->poll);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
55
56
57
58
59
  	return r;
  }
  #else
  #define proc_do_uts_string NULL
  #endif
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
60
61
  static DEFINE_CTL_TABLE_POLL(hostname_poll);
  static DEFINE_CTL_TABLE_POLL(domainname_poll);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
62
63
  static struct ctl_table uts_kern_table[] = {
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
64
65
66
67
68
  		.procname	= "ostype",
  		.data		= init_uts_ns.name.sysname,
  		.maxlen		= sizeof(init_uts_ns.name.sysname),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
69
70
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
71
72
73
74
75
  		.procname	= "osrelease",
  		.data		= init_uts_ns.name.release,
  		.maxlen		= sizeof(init_uts_ns.name.release),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
76
77
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
78
79
80
81
82
  		.procname	= "version",
  		.data		= init_uts_ns.name.version,
  		.maxlen		= sizeof(init_uts_ns.name.version),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
83
84
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
85
86
87
88
89
  		.procname	= "hostname",
  		.data		= init_uts_ns.name.nodename,
  		.maxlen		= sizeof(init_uts_ns.name.nodename),
  		.mode		= 0644,
  		.proc_handler	= proc_do_uts_string,
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
90
  		.poll		= &hostname_poll,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
91
92
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
93
94
95
96
97
  		.procname	= "domainname",
  		.data		= init_uts_ns.name.domainname,
  		.maxlen		= sizeof(init_uts_ns.name.domainname),
  		.mode		= 0644,
  		.proc_handler	= proc_do_uts_string,
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
98
  		.poll		= &domainname_poll,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
99
100
101
102
103
104
  	},
  	{}
  };
  
  static struct ctl_table uts_root_table[] = {
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
105
106
107
108
109
110
  		.procname	= "kernel",
  		.mode		= 0555,
  		.child		= uts_kern_table,
  	},
  	{}
  };
f1ecf0685   Lucas De Marchi   sysctl: add suppo...
111
112
113
114
115
116
117
118
119
120
121
122
  #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   Eric W. Biederman   [PATCH] sysctl: m...
123
124
  static int __init utsname_sysctl_init(void)
  {
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
125
  	register_sysctl_table(uts_root_table);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
126
127
  	return 0;
  }
95583e4ab   Fabian Frederick   kernel/utsname_sy...
128
  device_initcall(utsname_sysctl_init);