power.rs 534 B

123456789101112131415161718192021222324252627282930313233
  1. use nix::sys::reboot::RebootMode;
  2. pub fn shutdown() -> !{
  3. println!("system shutting down...");
  4. let _ = nix::sys::reboot::reboot(RebootMode::RB_POWER_OFF);
  5. loop {
  6. }
  7. }
  8. pub fn reboot() -> ! {
  9. println!("system rebooting...");
  10. let _ = nix::sys::reboot::reboot(RebootMode::RB_AUTOBOOT);
  11. loop {
  12. }
  13. }
  14. pub fn safe_shutdown() -> ! {
  15. sync();
  16. sync();
  17. sync();
  18. shutdown()
  19. }
  20. pub fn safe_reboot() -> ! {
  21. sync();
  22. sync();
  23. sync();
  24. reboot()
  25. }
  26. pub fn sync() {
  27. nix::unistd::sync();
  28. }