Commit 8218c74c authored by Serge E. Hallyn's avatar Serge E. Hallyn Committed by Linus Torvalds

[PATCH] namespaces: utsname: sysctl

Sysctl uts patch.  This will need to be done another way, but since sysctl
itself needs to be container aware, 'the right thing' is a separate patchset.

[akpm@osdl.org: ia64 build fix]
[sam.vilain@catalyst.net.nz: cleanup]
[sam.vilain@catalyst.net.nz: add proc_do_utsns_string]
Signed-off-by: default avatarSerge E. Hallyn <serue@us.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Andrey Savochkin <saw@sw.ru>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4865ecf1
...@@ -139,7 +139,7 @@ static int parse_table(int __user *, int, void __user *, size_t __user *, ...@@ -139,7 +139,7 @@ static int parse_table(int __user *, int, void __user *, size_t __user *,
void __user *, size_t, ctl_table *, void **); void __user *, size_t, ctl_table *, void **);
#endif #endif
static int proc_doutsstring(ctl_table *table, int write, struct file *filp, static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos); void __user *buffer, size_t *lenp, loff_t *ppos);
static ctl_table root_table[]; static ctl_table root_table[];
...@@ -229,51 +229,100 @@ static ctl_table root_table[] = { ...@@ -229,51 +229,100 @@ static ctl_table root_table[] = {
}; };
static ctl_table kern_table[] = { static ctl_table kern_table[] = {
#ifndef CONFIG_UTS_NS
{ {
.ctl_name = KERN_OSTYPE, .ctl_name = KERN_OSTYPE,
.procname = "ostype", .procname = "ostype",
.data = system_utsname.sysname, .data = init_uts_ns.name.sysname,
.maxlen = sizeof(system_utsname.sysname), .maxlen = sizeof(init_uts_ns.name.sysname),
.mode = 0444, .mode = 0444,
.proc_handler = &proc_doutsstring, .proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string, .strategy = &sysctl_string,
}, },
{ {
.ctl_name = KERN_OSRELEASE, .ctl_name = KERN_OSRELEASE,
.procname = "osrelease", .procname = "osrelease",
.data = system_utsname.release, .data = init_uts_ns.name.release,
.maxlen = sizeof(system_utsname.release), .maxlen = sizeof(init_uts_ns.name.release),
.mode = 0444, .mode = 0444,
.proc_handler = &proc_doutsstring, .proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string, .strategy = &sysctl_string,
}, },
{ {
.ctl_name = KERN_VERSION, .ctl_name = KERN_VERSION,
.procname = "version", .procname = "version",
.data = system_utsname.version, .data = init_uts_ns.name.version,
.maxlen = sizeof(system_utsname.version), .maxlen = sizeof(init_uts_ns.name.version),
.mode = 0444, .mode = 0444,
.proc_handler = &proc_doutsstring, .proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string, .strategy = &sysctl_string,
}, },
{ {
.ctl_name = KERN_NODENAME, .ctl_name = KERN_NODENAME,
.procname = "hostname", .procname = "hostname",
.data = system_utsname.nodename, .data = init_uts_ns.name.nodename,
.maxlen = sizeof(system_utsname.nodename), .maxlen = sizeof(init_uts_ns.name.nodename),
.mode = 0644, .mode = 0644,
.proc_handler = &proc_doutsstring, .proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string, .strategy = &sysctl_string,
}, },
{ {
.ctl_name = KERN_DOMAINNAME, .ctl_name = KERN_DOMAINNAME,
.procname = "domainname", .procname = "domainname",
.data = system_utsname.domainname, .data = init_uts_ns.name.domainname,
.maxlen = sizeof(system_utsname.domainname), .maxlen = sizeof(init_uts_ns.name.domainname),
.mode = 0644, .mode = 0644,
.proc_handler = &proc_doutsstring, .proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string, .strategy = &sysctl_string,
}, },
#else /* !CONFIG_UTS_NS */
{
.ctl_name = KERN_OSTYPE,
.procname = "ostype",
.data = NULL,
/* could maybe use __NEW_UTS_LEN here? */
.maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
.mode = 0444,
.proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string,
},
{
.ctl_name = KERN_OSRELEASE,
.procname = "osrelease",
.data = NULL,
.maxlen = FIELD_SIZEOF(struct new_utsname, release),
.mode = 0444,
.proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string,
},
{
.ctl_name = KERN_VERSION,
.procname = "version",
.data = NULL,
.maxlen = FIELD_SIZEOF(struct new_utsname, version),
.mode = 0444,
.proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string,
},
{
.ctl_name = KERN_NODENAME,
.procname = "hostname",
.data = NULL,
.maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
.mode = 0644,
.proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string,
},
{
.ctl_name = KERN_DOMAINNAME,
.procname = "domainname",
.data = NULL,
.maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
.mode = 0644,
.proc_handler = &proc_do_uts_string,
.strategy = &sysctl_string,
},
#endif /* !CONFIG_UTS_NS */
{ {
.ctl_name = KERN_PANIC, .ctl_name = KERN_PANIC,
.procname = "panic", .procname = "panic",
...@@ -1704,7 +1753,8 @@ int proc_dostring(ctl_table *table, int write, struct file *filp, ...@@ -1704,7 +1753,8 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
* to observe. Should this be in kernel/sys.c ???? * to observe. Should this be in kernel/sys.c ????
*/ */
static int proc_doutsstring(ctl_table *table, int write, struct file *filp, #ifndef CONFIG_UTS_NS
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
int r; int r;
...@@ -1720,6 +1770,48 @@ static int proc_doutsstring(ctl_table *table, int write, struct file *filp, ...@@ -1720,6 +1770,48 @@ static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
} }
return r; return r;
} }
#else /* !CONFIG_UTS_NS */
static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
int r;
struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
char* which;
switch (table->ctl_name) {
case KERN_OSTYPE:
which = uts_ns->name.sysname;
break;
case KERN_NODENAME:
which = uts_ns->name.nodename;
break;
case KERN_OSRELEASE:
which = uts_ns->name.release;
break;
case KERN_VERSION:
which = uts_ns->name.version;
break;
case KERN_DOMAINNAME:
which = uts_ns->name.domainname;
break;
default:
r = -EINVAL;
goto out;
}
if (!write) {
down_read(&uts_sem);
r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
up_read(&uts_sem);
} else {
down_write(&uts_sem);
r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
up_write(&uts_sem);
}
out:
return r;
}
#endif /* !CONFIG_UTS_NS */
static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
int *valp, int *valp,
...@@ -2283,12 +2375,20 @@ int proc_dostring(ctl_table *table, int write, struct file *filp, ...@@ -2283,12 +2375,20 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
return -ENOSYS; return -ENOSYS;
} }
static int proc_doutsstring(ctl_table *table, int write, struct file *filp, static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
return -ENOSYS; return -ENOSYS;
} }
#ifdef CONFIG_SYSVIPC
static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
return -ENOSYS;
}
#endif
int proc_dointvec(ctl_table *table, int write, struct file *filp, int proc_dointvec(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment