0001
0002
0003
0004
0005
0006 #include <linux/ctype.h>
0007 #include <linux/init.h>
0008 #include <linux/kernel.h>
0009 #include <linux/module.h>
0010 #include <linux/proc_fs.h>
0011 #include <linux/seq_file.h>
0012 #include <linux/types.h>
0013 #include <linux/uaccess.h>
0014
0015
0016
0017
0018
0019 int uml_exitcode = 0;
0020
0021 static int exitcode_proc_show(struct seq_file *m, void *v)
0022 {
0023 int val;
0024
0025
0026
0027
0028
0029 val = uml_exitcode;
0030 seq_printf(m, "%d\n", val);
0031 return 0;
0032 }
0033
0034 static int exitcode_proc_open(struct inode *inode, struct file *file)
0035 {
0036 return single_open(file, exitcode_proc_show, NULL);
0037 }
0038
0039 static ssize_t exitcode_proc_write(struct file *file,
0040 const char __user *buffer, size_t count, loff_t *pos)
0041 {
0042 char *end, buf[sizeof("nnnnn\0")];
0043 size_t size;
0044 int tmp;
0045
0046 size = min(count, sizeof(buf));
0047 if (copy_from_user(buf, buffer, size))
0048 return -EFAULT;
0049
0050 tmp = simple_strtol(buf, &end, 0);
0051 if ((*end != '\0') && !isspace(*end))
0052 return -EINVAL;
0053
0054 uml_exitcode = tmp;
0055 return count;
0056 }
0057
0058 static const struct proc_ops exitcode_proc_ops = {
0059 .proc_open = exitcode_proc_open,
0060 .proc_read = seq_read,
0061 .proc_lseek = seq_lseek,
0062 .proc_release = single_release,
0063 .proc_write = exitcode_proc_write,
0064 };
0065
0066 static int make_proc_exitcode(void)
0067 {
0068 struct proc_dir_entry *ent;
0069
0070 ent = proc_create("exitcode", 0600, NULL, &exitcode_proc_ops);
0071 if (ent == NULL) {
0072 printk(KERN_WARNING "make_proc_exitcode : Failed to register "
0073 "/proc/exitcode\n");
0074 return 0;
0075 }
0076 return 0;
0077 }
0078
0079 __initcall(make_proc_exitcode);