summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys/mod.rs3
-rw-r--r--src/sys/reboot.rs36
2 files changed, 39 insertions, 0 deletions
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 82934164..b59ca9b1 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -31,6 +31,9 @@ pub mod stat;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod syscall;
+#[cfg(any(target_os = "linux", target_os = "android"))]
+pub mod reboot;
+
#[cfg(not(target_os = "ios"))]
pub mod termios;
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;
+ }
+}