at v3.11 1.7 kB view raw
1/* 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 * Licensed under the GPL 4 */ 5 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 <asm/uaccess.h> 14 15/* 16 * If read and write race, the read will still atomically read a valid 17 * value. 18 */ 19int uml_exitcode = 0; 20 21static int exitcode_proc_show(struct seq_file *m, void *v) 22{ 23 int val; 24 25 /* 26 * Save uml_exitcode in a local so that we don't need to guarantee 27 * that sprintf accesses it atomically. 28 */ 29 val = uml_exitcode; 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); 37} 38 39static ssize_t exitcode_proc_write(struct file *file, 40 const char __user *buffer, size_t count, loff_t *pos) 41{ 42 char *end, buf[sizeof("nnnnn\0")]; 43 int tmp; 44 45 if (copy_from_user(buf, buffer, count)) 46 return -EFAULT; 47 48 tmp = simple_strtol(buf, &end, 0); 49 if ((*end != '\0') && !isspace(*end)) 50 return -EINVAL; 51 52 uml_exitcode = tmp; 53 return count; 54} 55 56static const struct file_operations exitcode_proc_fops = { 57 .owner = THIS_MODULE, 58 .open = exitcode_proc_open, 59 .read = seq_read, 60 .llseek = seq_lseek, 61 .release = single_release, 62 .write = exitcode_proc_write, 63}; 64 65static int make_proc_exitcode(void) 66{ 67 struct proc_dir_entry *ent; 68 69 ent = proc_create("exitcode", 0600, NULL, &exitcode_proc_fops); 70 if (ent == NULL) { 71 printk(KERN_WARNING "make_proc_exitcode : Failed to register " 72 "/proc/exitcode\n"); 73 return 0; 74 } 75 return 0; 76} 77 78__initcall(make_proc_exitcode);