Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / um / kernel / exitcode.c
blob546302e3b7fbf0db7fef2faf9e5b77695f312c3e
1 /*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/ctype.h>
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include <linux/types.h>
13 #include <linux/uaccess.h>
16 * If read and write race, the read will still atomically read a valid
17 * value.
19 int uml_exitcode = 0;
21 static int exitcode_proc_show(struct seq_file *m, void *v)
23 int val;
26 * Save uml_exitcode in a local so that we don't need to guarantee
27 * that sprintf accesses it atomically.
29 val = uml_exitcode;
30 seq_printf(m, "%d\n", val);
31 return 0;
34 static int exitcode_proc_open(struct inode *inode, struct file *file)
36 return single_open(file, exitcode_proc_show, NULL);
39 static ssize_t exitcode_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos)
42 char *end, buf[sizeof("nnnnn\0")];
43 size_t size;
44 int tmp;
46 size = min(count, sizeof(buf));
47 if (copy_from_user(buf, buffer, size))
48 return -EFAULT;
50 tmp = simple_strtol(buf, &end, 0);
51 if ((*end != '\0') && !isspace(*end))
52 return -EINVAL;
54 uml_exitcode = tmp;
55 return count;
58 static const struct file_operations exitcode_proc_fops = {
59 .owner = THIS_MODULE,
60 .open = exitcode_proc_open,
61 .read = seq_read,
62 .llseek = seq_lseek,
63 .release = single_release,
64 .write = exitcode_proc_write,
67 static int make_proc_exitcode(void)
69 struct proc_dir_entry *ent;
71 ent = proc_create("exitcode", 0600, NULL, &exitcode_proc_fops);
72 if (ent == NULL) {
73 printk(KERN_WARNING "make_proc_exitcode : Failed to register "
74 "/proc/exitcode\n");
75 return 0;
77 return 0;
80 __initcall(make_proc_exitcode);