summaryrefslogtreecommitdiff
path: root/src/sys/reboot.rs
blob: d537401f6f35176f5678c0d8eaea06f03457b794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
    }
}