• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::fs::File;
2 
3 use rustix::fd::AsFd;
4 #[cfg(not(target_os = "android"))]
5 use rustix::fd::{FromRawFd, OwnedFd, RawFd};
6 #[cfg(not(target_os = "android"))]
7 use rustix::thread::*;
8 
9 #[test]
10 #[ignore = "Requires CAP_SYS_ADMIN capability"]
test_move_into_link_name_space()11 fn test_move_into_link_name_space() {
12     let f = File::open("/proc/self/ns/uts").unwrap();
13 
14     rustix::thread::move_into_link_name_space(
15         f.as_fd(),
16         Some(rustix::thread::LinkNameSpaceType::HostNameAndNISDomainName),
17     )
18     .unwrap();
19 }
20 
21 #[test]
22 #[ignore = "Requires CAP_SYS_ADMIN capability"]
23 #[cfg(not(target_os = "android"))] // Android libc bindings don't have `SYS_pidfd_open` yet.
test_move_into_thread_name_spaces()24 fn test_move_into_thread_name_spaces() {
25     let fd = unsafe { libc::syscall(libc::SYS_pidfd_open, std::process::id() as usize, 0_usize) };
26     if fd == -1 {
27         panic!("{}", std::io::Error::last_os_error());
28     }
29 
30     let fd = unsafe { OwnedFd::from_raw_fd(fd as RawFd) };
31 
32     rustix::thread::move_into_thread_name_spaces(
33         fd.as_fd(),
34         ThreadNameSpaceType::HOST_NAME_AND_NIS_DOMAIN_NAME,
35     )
36     .unwrap();
37 }
38