1use crate::Result;
4use crate::errno::Errno;
5use std::convert::Infallible;
6use std::mem::drop;
7
8libc_enum! {
9 #[repr(i32)]
14 #[non_exhaustive]
15 pub enum RebootMode {
16 RB_HALT_SYSTEM,
17 RB_KEXEC,
18 RB_POWER_OFF,
19 RB_AUTOBOOT,
20 RB_SW_SUSPEND,
22 }
23}
24
25pub fn reboot(how: RebootMode) -> Result<Infallible> {
26 unsafe {
27 libc::reboot(how as libc::c_int)
28 };
29 Err(Errno::last())
30}
31
32pub fn set_cad_enabled(enable: bool) -> Result<()> {
36 let cmd = if enable {
37 libc::RB_ENABLE_CAD
38 } else {
39 libc::RB_DISABLE_CAD
40 };
41 let res = unsafe {
42 libc::reboot(cmd)
43 };
44 Errno::result(res).map(drop)
45}