-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |