exitcode.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/init.h"
  6. #include "linux/ctype.h"
  7. #include "linux/proc_fs.h"
  8. #include "asm/uaccess.h"
  9. /* If read and write race, the read will still atomically read a valid
  10. * value.
  11. */
  12. int uml_exitcode = 0;
  13. static int read_proc_exitcode(char *page, char **start, off_t off,
  14. int count, int *eof, void *data)
  15. {
  16. int len;
  17. len = sprintf(page, "%d\n", uml_exitcode);
  18. len -= off;
  19. if(len <= off+count) *eof = 1;
  20. *start = page + off;
  21. if(len > count) len = count;
  22. if(len < 0) len = 0;
  23. return(len);
  24. }
  25. static int write_proc_exitcode(struct file *file, const char __user *buffer,
  26. unsigned long count, void *data)
  27. {
  28. char *end, buf[sizeof("nnnnn\0")];
  29. int tmp;
  30. if(copy_from_user(buf, buffer, count))
  31. return(-EFAULT);
  32. tmp = simple_strtol(buf, &end, 0);
  33. if((*end != '\0') && !isspace(*end))
  34. return(-EINVAL);
  35. uml_exitcode = tmp;
  36. return(count);
  37. }
  38. static int make_proc_exitcode(void)
  39. {
  40. struct proc_dir_entry *ent;
  41. ent = create_proc_entry("exitcode", 0600, &proc_root);
  42. if(ent == NULL){
  43. printk(KERN_WARNING "make_proc_exitcode : Failed to register "
  44. "/proc/exitcode\n");
  45. return(0);
  46. }
  47. ent->read_proc = read_proc_exitcode;
  48. ent->write_proc = write_proc_exitcode;
  49. return(0);
  50. }
  51. __initcall(make_proc_exitcode);
  52. /*
  53. * Overrides for Emacs so that we follow Linus's tabbing style.
  54. * Emacs will notice this stuff at the end of the file and automatically
  55. * adjust the settings for this buffer only. This must remain at the end
  56. * of the file.
  57. * ---------------------------------------------------------------------------
  58. * Local variables:
  59. * c-file-style: "linux"
  60. * End:
  61. */