From f3d7b013be7f5ae948045cdee6accd7a64e8ae4c Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Mon, 11 Jul 2016 19:01:15 +0300 Subject: Add the initial implementation of reboot() --- src/sys/reboot.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/sys/reboot.rs (limited to 'src/sys/reboot.rs') 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 { + 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; + } +} -- cgit v1.2.3