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
37
38
39
40
41
42
43
44
45
use crate::{Error, Result};
use crate::errno::Errno;
use libc;
use std::convert::Infallible;
use std::mem::drop;
libc_enum! {
#[repr(i32)]
pub enum RebootMode {
RB_HALT_SYSTEM,
RB_KEXEC,
RB_POWER_OFF,
RB_AUTOBOOT,
RB_SW_SUSPEND,
}
}
pub fn reboot(how: RebootMode) -> Result<Infallible> {
unsafe {
libc::reboot(how as libc::c_int)
};
Err(Error::from(Errno::last()))
}
pub fn set_cad_enabled(enable: bool) -> Result<()> {
let cmd = if enable {
libc::RB_ENABLE_CAD
} else {
libc::RB_DISABLE_CAD
};
let res = unsafe {
libc::reboot(cmd)
};
Errno::result(res).map(drop)
}