From 12e5c16eccd8f17c0d892b0216051799217d1903 Mon Sep 17 00:00:00 2001 From: Federico Maria Morrone Date: Sun, 24 Sep 2023 21:01:14 +0200 Subject: [PATCH] Add test for reboot syscall --- tests/system/main.rs | 2 ++ tests/system/reboot.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/system/reboot.rs diff --git a/tests/system/main.rs b/tests/system/main.rs index 4146c9e96..a8ad6120f 100644 --- a/tests/system/main.rs +++ b/tests/system/main.rs @@ -3,6 +3,8 @@ #![cfg(feature = "system")] #![cfg(not(any(windows, target_os = "wasi")))] +#[cfg(target_os = "linux")] +mod reboot; #[cfg(linux_kernel)] mod sysinfo; mod uname; diff --git a/tests/system/reboot.rs b/tests/system/reboot.rs new file mode 100644 index 000000000..fe5c4e80f --- /dev/null +++ b/tests/system/reboot.rs @@ -0,0 +1,18 @@ +#[test] +#[cfg(feature = "thread")] +fn test_reboot() { + use rustix::{ + io::Errno, + system::{self, RebootCommand}, + thread::{self, CapabilityFlags}, + }; + + let mut capabilities = thread::capabilities(None).expect("Failed to get capabilities"); + + capabilities.effective.set(CapabilityFlags::SYS_BOOT, false); + + thread::set_capabilities(None, capabilities).expect("Failed to set capabilities"); + + // The reboot syscall requires the CAP_SYS_BOOT permission to be called, otherwise EPERM is returned + assert_eq!(system::reboot(RebootCommand::Restart), Err(Errno::PERM)); +}