summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys/reboot.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/sys/reboot.rs b/src/sys/reboot.rs
index 10abef91..82a31380 100644
--- a/src/sys/reboot.rs
+++ b/src/sys/reboot.rs
@@ -1,41 +1,37 @@
use {Errno, Error, Result};
-use libc::c_int;
+use libc;
use void::Void;
use std::mem::drop;
-#[allow(overflowing_literals)]
+#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum RebootMode {
- Halt = 0xcdef0123,
- kexec = 0x45584543,
- PowerOff = 0x4321fedc,
- Restart = 0x1234567,
+ Halt = libc::RB_HALT_SYSTEM,
+ kexec = libc::RB_KEXEC,
+ PowerOff = libc::RB_POWER_OFF,
+ Restart = libc::RB_AUTOBOOT,
// we do not support Restart2,
- Suspend = 0xd000fce1,
+ Suspend = libc::RB_SW_SUSPEND,
}
pub fn reboot(how: RebootMode) -> Result<Void> {
unsafe {
- ext::reboot(how as c_int)
+ libc::reboot(how as libc::c_int)
};
Err(Error::Sys(Errno::last()))
}
-
/// Enable or disable the reboot keystroke (Ctrl-Alt-Delete).
///
/// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C.
-#[allow(overflowing_literals)]
pub fn set_cad_enabled(enable: bool) -> Result<()> {
+ let cmd = if enable {
+ libc::RB_ENABLE_CAD
+ } else {
+ libc::RB_DISABLE_CAD
+ };
let res = unsafe {
- ext::reboot(if enable { 0x89abcdef } else { 0 })
+ libc::reboot(cmd)
};
Errno::result(res).map(drop)
}
-
-mod ext {
- use libc::c_int;
- extern {
- pub fn reboot(cmd: c_int) -> c_int;
- }
-}