diff options
Diffstat (limited to 'src/sys/reboot.rs')
-rw-r--r-- | src/sys/reboot.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/sys/reboot.rs b/src/sys/reboot.rs new file mode 100644 index 00000000..d537401f --- /dev/null +++ b/src/sys/reboot.rs @@ -0,0 +1,36 @@ +use {Errno, Error, Result}; +use libc::c_int; +use void::Void; +use std::mem::drop; + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum RebootMode { + Halt = 0xcdef0123, + kexec = 0x45584543, + PowerOff = 0x4321fedc, + Restart = 0x1234567, + // we do not support Restart2, + Suspend = 0xd000fce1, +} + +pub fn reboot(how: RebootMode) -> Result<Void> { + unsafe { + ext::reboot(how as c_int) + }; + Err(Error::Sys(Errno::last())) +} + +#[allow(overflowing_literals)] +pub fn set_cad_enabled(enable: bool) -> Result<()> { + let res = unsafe { + ext::reboot(if enable { 0x89abcdef } else { 0 }) + }; + Errno::result(res).map(drop) +} + +mod ext { + use libc::c_int; + extern { + pub fn reboot(cmd: c_int) -> c_int; + } +} |