1 //! Reboot/shutdown or enable/disable Ctrl-Alt-Delete. 2 3 use crate::Result; 4 use crate::errno::Errno; 5 use std::convert::Infallible; 6 use std::mem::drop; 7 8 libc_enum! { 9 /// How exactly should the system be rebooted. 10 /// 11 /// See [`set_cad_enabled()`](fn.set_cad_enabled.html) for 12 /// enabling/disabling Ctrl-Alt-Delete. 13 #[repr(i32)] 14 #[non_exhaustive] 15 pub enum RebootMode { 16 RB_HALT_SYSTEM, 17 RB_KEXEC, 18 RB_POWER_OFF, 19 RB_AUTOBOOT, 20 // we do not support Restart2, 21 RB_SW_SUSPEND, 22 } 23 } 24 reboot(how: RebootMode) -> Result<Infallible>25pub fn reboot(how: RebootMode) -> Result<Infallible> { 26 unsafe { 27 libc::reboot(how as libc::c_int) 28 }; 29 Err(Errno::last()) 30 } 31 32 /// Enable or disable the reboot keystroke (Ctrl-Alt-Delete). 33 /// 34 /// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C. set_cad_enabled(enable: bool) -> Result<()>35pub fn set_cad_enabled(enable: bool) -> Result<()> { 36 let cmd = if enable { 37 libc::RB_ENABLE_CAD 38 } else { 39 libc::RB_DISABLE_CAD 40 }; 41 let res = unsafe { 42 libc::reboot(cmd) 43 }; 44 Errno::result(res).map(drop) 45 } 46