2 * linux/kernel/sysctl.c
4 * Virtual Context Support
6 * Copyright (C) 2004 Herbert Pƶtzl
8 * V0.01 basic structure
12 #include <linux/config.h>
13 #include <linux/errno.h>
14 #include <linux/vserver.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/ctype.h>
18 #include <linux/sysctl.h>
21 #include <asm/uaccess.h>
22 #include <asm/unistd.h>
25 #define CTL_VSERVER 4242 /* unused? */
33 unsigned int vx_debug_switch = 0;
34 unsigned int vx_debug_limit = 0;
37 static struct ctl_table_header *vserver_table_header;
38 static ctl_table vserver_table[];
41 void vserver_register_sysctl(void)
43 if (!vserver_table_header) {
44 vserver_table_header = register_sysctl_table(vserver_table, 1);
46 // if (vserver_table[0].de)
47 // vserver_table[0].de->owner = THIS_MODULE;
53 void vserver_unregister_sysctl(void)
55 if (vserver_table_header) {
56 unregister_sysctl_table(vserver_table_header);
57 vserver_table_header = NULL;
62 static int proc_dodebug(ctl_table *table, int write,
63 struct file *file, void *buffer, size_t *lenp)
65 char tmpbuf[20], *p, c;
69 if ((file->f_pos && !write) || !*lenp) {
77 if (!access_ok(VERIFY_READ, buffer, left))
80 while (left && __get_user(c, p) >= 0 && isspace(c))
85 if (left > sizeof(tmpbuf) - 1)
87 if (copy_from_user(tmpbuf, p, left))
91 for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
92 value = 10 * value + (*p - '0');
93 if (*p && !isspace(*p))
95 while (left && isspace(*p))
97 *(unsigned int *) table->data = value;
99 if (!access_ok(VERIFY_WRITE, buffer, left))
101 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
104 if (__copy_to_user(buffer, tmpbuf, len))
106 if ((left -= len) > 0) {
107 if (put_user('\n', (char *)buffer + len))
115 file->f_pos += *lenp;
121 static ctl_table debug_table[] = {
123 .ctl_name = CTL_DEBUG_SWITCH,
124 .procname = "debug_switch",
125 .data = &vx_debug_switch,
126 .maxlen = sizeof(int),
128 .proc_handler = &proc_dodebug
131 .ctl_name = CTL_DEBUG_LIMIT,
132 .procname = "debug_limit",
133 .data = &vx_debug_limit,
134 .maxlen = sizeof(int),
136 .proc_handler = &proc_dodebug
141 static ctl_table vserver_table[] = {
143 .ctl_name = CTL_VSERVER,
144 .procname = "vserver",