poweroff.c 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * poweroff.c - sysrq handler to gracefully power down machine.
  3. *
  4. * This file is released under the GPL v2
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/sysrq.h>
  8. #include <linux/init.h>
  9. #include <linux/pm.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/reboot.h>
  12. /*
  13. * When the user hits Sys-Rq o to power down the machine this is the
  14. * callback we use.
  15. */
  16. static void do_poweroff(struct work_struct *dummy)
  17. {
  18. kernel_power_off();
  19. }
  20. static DECLARE_WORK(poweroff_work, do_poweroff);
  21. static void handle_poweroff(int key, struct tty_struct *tty)
  22. {
  23. schedule_work(&poweroff_work);
  24. }
  25. static struct sysrq_key_op sysrq_poweroff_op = {
  26. .handler = handle_poweroff,
  27. .help_msg = "powerOff",
  28. .action_msg = "Power Off",
  29. .enable_mask = SYSRQ_ENABLE_BOOT,
  30. };
  31. static int pm_sysrq_init(void)
  32. {
  33. register_sysrq_key('o', &sysrq_poweroff_op);
  34. return 0;
  35. }
  36. subsys_initcall(pm_sysrq_init);