Skip to content

Commit

Permalink
Manually match on RebootMode::*
Browse files Browse the repository at this point in the history
  • Loading branch information
bugaevc committed Jul 13, 2016
1 parent b19afe5 commit 012c662
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/sys/reboot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ use libc;
use void::Void;
use std::mem::drop;

#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum RebootMode {
Halt = libc::RB_HALT_SYSTEM,
kexec = libc::RB_KEXEC,
PowerOff = libc::RB_POWER_OFF,
Restart = libc::RB_AUTOBOOT,
Halt,
kexec,
PowerOff,
Restart,
// we do not support Restart2,
Suspend = libc::RB_SW_SUSPEND,
Suspend,
}

pub fn reboot(how: RebootMode) -> Result<Void> {
let cmd = match how {
RebootMode::Halt => libc::RB_HALT_SYSTEM,
RebootMode::kexec => libc::RB_KEXEC,
RebootMode::PowerOff => libc::RB_POWER_OFF,
RebootMode::Restart => libc::RB_AUTOBOOT,
// we do not support Restart2,
RebootMode::Suspend => libc::RB_SW_SUSPEND,
};
unsafe {
libc::reboot(how as libc::c_int)
libc::reboot(cmd)
};
Err(Error::Sys(Errno::last()))
}
Expand Down

0 comments on commit 012c662

Please sign in to comment.