diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2016-07-11 19:01:15 +0300 |
---|---|---|
committer | Sergey Bugaev <bugaevc@gmail.com> | 2016-07-13 10:19:37 +0300 |
commit | f3d7b013be7f5ae948045cdee6accd7a64e8ae4c (patch) | |
tree | 0c462a3c4092f3abb06d0d94b8b3c747783c46c3 /src/sys/reboot.rs | |
parent | 1033385d17ec1faad8899154acc79b52f2f6c2da (diff) | |
download | nix-f3d7b013be7f5ae948045cdee6accd7a64e8ae4c.zip |
Add the initial implementation of reboot()
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; + } +} |