Skip to content

Commit

Permalink
Add test for reboot syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Sep 24, 2023
1 parent 288da85 commit 12e5c16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/system/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 18 additions & 0 deletions tests/system/reboot.rs
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit 12e5c16

Please sign in to comment.