]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/um/kernel/exitcode.c
Replace <asm/uaccess.h> with <linux/uaccess.h> globally
[mirror_ubuntu-jammy-kernel.git] / arch / um / kernel / exitcode.c
CommitLineData
e16f5350 1/*
c5d4bb17 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
1da177e4
LT
3 * Licensed under the GPL
4 */
5
c5d4bb17
JD
6#include <linux/ctype.h>
7#include <linux/init.h>
8#include <linux/kernel.h>
6613c5e8 9#include <linux/module.h>
c5d4bb17 10#include <linux/proc_fs.h>
6613c5e8 11#include <linux/seq_file.h>
c5d4bb17 12#include <linux/types.h>
7c0f6ba6 13#include <linux/uaccess.h>
1da177e4 14
c5d4bb17
JD
15/*
16 * If read and write race, the read will still atomically read a valid
1da177e4
LT
17 * value.
18 */
19int uml_exitcode = 0;
20
6613c5e8 21static int exitcode_proc_show(struct seq_file *m, void *v)
1da177e4 22{
6613c5e8 23 int val;
1da177e4 24
c5d4bb17
JD
25 /*
26 * Save uml_exitcode in a local so that we don't need to guarantee
730760e9
JD
27 * that sprintf accesses it atomically.
28 */
29 val = uml_exitcode;
6613c5e8
AD
30 seq_printf(m, "%d\n", val);
31 return 0;
32}
33
34static int exitcode_proc_open(struct inode *inode, struct file *file)
35{
36 return single_open(file, exitcode_proc_show, NULL);
1da177e4
LT
37}
38
6613c5e8
AD
39static ssize_t exitcode_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos)
1da177e4
LT
41{
42 char *end, buf[sizeof("nnnnn\0")];
201f99f1 43 size_t size;
1da177e4
LT
44 int tmp;
45
201f99f1
DC
46 size = min(count, sizeof(buf));
47 if (copy_from_user(buf, buffer, size))
e16f5350
JD
48 return -EFAULT;
49
1da177e4 50 tmp = simple_strtol(buf, &end, 0);
c5d4bb17 51 if ((*end != '\0') && !isspace(*end))
e16f5350
JD
52 return -EINVAL;
53
1da177e4 54 uml_exitcode = tmp;
e16f5350 55 return count;
1da177e4
LT
56}
57
6613c5e8
AD
58static 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,
65};
66
1da177e4
LT
67static int make_proc_exitcode(void)
68{
69 struct proc_dir_entry *ent;
70
6613c5e8 71 ent = proc_create("exitcode", 0600, NULL, &exitcode_proc_fops);
c5d4bb17 72 if (ent == NULL) {
30f417c6 73 printk(KERN_WARNING "make_proc_exitcode : Failed to register "
1da177e4 74 "/proc/exitcode\n");
e16f5350 75 return 0;
1da177e4 76 }
e16f5350 77 return 0;
1da177e4
LT
78}
79
80__initcall(make_proc_exitcode);