exitcode.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, val;
  17. /* Save uml_exitcode in a local so that we don't need to guarantee
  18. * that sprintf accesses it atomically.
  19. */
  20. val = uml_exitcode;
  21. len = sprintf(page, "%d\n", val);
  22. len -= off;
  23. if(len <= off+count) *eof = 1;
  24. *start = page + off;
  25. if(len > count) len = count;
  26. if(len < 0) len = 0;
  27. return(len);
  28. }
  29. static int write_proc_exitcode(struct file *file, const char __user *buffer,
  30. unsigned long count, void *data)
  31. {
  32. char *end, buf[sizeof("nnnnn\0")];
  33. int tmp;
  34. if(copy_from_user(buf, buffer, count))
  35. return(-EFAULT);
  36. tmp = simple_strtol(buf, &end, 0);
  37. if((*end != '\0') && !isspace(*end))
  38. return(-EINVAL);
  39. uml_exitcode = tmp;
  40. return(count);
  41. }
  42. static int make_proc_exitcode(void)
  43. {
  44. struct proc_dir_entry *ent;
  45. ent = create_proc_entry("exitcode", 0600, &proc_root);
  46. if(ent == NULL){
  47. printk(KERN_WARNING "make_proc_exitcode : Failed to register "
  48. "/proc/exitcode\n");
  49. return(0);
  50. }
  51. ent->read_proc = read_proc_exitcode;
  52. ent->write_proc = write_proc_exitcode;
  53. return(0);
  54. }
  55. __initcall(make_proc_exitcode);
  56. /*
  57. * Overrides for Emacs so that we follow Linus's tabbing style.
  58. * Emacs will notice this stuff at the end of the file and automatically
  59. * adjust the settings for this buffer only. This must remain at the end
  60. * of the file.
  61. * ---------------------------------------------------------------------------
  62. * Local variables:
  63. * c-file-style: "linux"
  64. * End:
  65. */