1 //! Reboot/shutdown or enable/disable Ctrl-Alt-Delete.
2
3 use {Errno, Error, Result};
4 use libc;
5 use void::Void;
6 use std::mem::drop;
7
8 /// How exactly should the system be rebooted.
9 ///
10 /// See [`set_cad_enabled()`](fn.set_cad_enabled.html) for
11 /// enabling/disabling Ctrl-Alt-Delete.
12 #[repr(i32)]
13 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
14 pub enum RebootMode {
15 RB_HALT_SYSTEM = libc::RB_HALT_SYSTEM,
16 RB_KEXEC = libc::RB_KEXEC,
17 RB_POWER_OFF = libc::RB_POWER_OFF,
18 RB_AUTOBOOT = libc::RB_AUTOBOOT,
19 // we do not support Restart2,
20 RB_SW_SUSPEND = libc::RB_SW_SUSPEND,
21 }
22
reboot(how: RebootMode) -> Result<Void>23 pub fn reboot(how: RebootMode) -> Result<Void> {
24 unsafe {
25 libc::reboot(how as libc::c_int)
26 };
27 Err(Error::Sys(Errno::last()))
28 }
29
30 /// Enable or disable the reboot keystroke (Ctrl-Alt-Delete).
31 ///
32 /// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C.
set_cad_enabled(enable: bool) -> Result<()>33 pub fn set_cad_enabled(enable: bool) -> Result<()> {
34 let cmd = if enable {
35 libc::RB_ENABLE_CAD
36 } else {
37 libc::RB_DISABLE_CAD
38 };
39 let res = unsafe {
40 libc::reboot(cmd)
41 };
42 Errno::result(res).map(drop)
43 }
44