poweroff.c 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(void *dummy)
  17. {
  18. kernel_power_off();
  19. }
  20. static DECLARE_WORK(poweroff_work, do_poweroff, NULL);
  21. static void handle_poweroff(int key, struct pt_regs *pt_regs,
  22. struct tty_struct *tty)
  23. {
  24. schedule_work(&poweroff_work);
  25. }
  26. static struct sysrq_key_op sysrq_poweroff_op = {
  27. .handler = handle_poweroff,
  28. .help_msg = "powerOff",
  29. .action_msg = "Power Off",
  30. .enable_mask = SYSRQ_ENABLE_BOOT,
  31. };
  32. static int pm_sysrq_init(void)
  33. {
  34. register_sysrq_key('o', &sysrq_poweroff_op);
  35. return 0;
  36. }
  37. subsys_initcall(pm_sysrq_init);