2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
6 #include <linux/ctype.h>
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/proc_fs.h>
10 #include <linux/types.h>
11 #include <asm/uaccess.h>
14 * If read and write race, the read will still atomically read a valid
19 static int read_proc_exitcode(char *page
, char **start
, off_t off
,
20 int count
, int *eof
, void *data
)
25 * Save uml_exitcode in a local so that we don't need to guarantee
26 * that sprintf accesses it atomically.
29 len
= sprintf(page
, "%d\n", val
);
41 static int write_proc_exitcode(struct file
*file
, const char __user
*buffer
,
42 unsigned long count
, void *data
)
44 char *end
, buf
[sizeof("nnnnn\0")];
47 if (copy_from_user(buf
, buffer
, count
))
50 tmp
= simple_strtol(buf
, &end
, 0);
51 if ((*end
!= '\0') && !isspace(*end
))
58 static int make_proc_exitcode(void)
60 struct proc_dir_entry
*ent
;
62 ent
= create_proc_entry("exitcode", 0600, NULL
);
64 printk(KERN_WARNING
"make_proc_exitcode : Failed to register "
69 ent
->read_proc
= read_proc_exitcode
;
70 ent
->write_proc
= write_proc_exitcode
;
75 __initcall(make_proc_exitcode
);