Skip to content

Commit

Permalink
is_proc_handl
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekko0114 committed Jun 7, 2024
1 parent 764aac9 commit 9c31834
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion experiment/selinux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ autoexamples = true
keywords = ["youki", "container", "selinux"]

[dependencies]
nix = { version = "0.29.0", features = ["process"] }
nix = { version = "0.29.0", features = ["process", "fs"] }
23 changes: 21 additions & 2 deletions experiment/selinux/src/selinux.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::sync::Once;
use crate::xattr::*;
use nix::unistd::gettid;
use nix::sys::statfs;
use nix::errno::Errno;
use std::path::PathBuf;
use std::fs::File;
use std::io::{self, Read};
use std::os::fd::{AsFd, AsRawFd};

const XATTR_NAME_SELINUX: &str = "security.selinux";
const ERR_EMPTY_PATH: &str = "empty path";
Expand Down Expand Up @@ -203,8 +206,24 @@ pub fn write_con(fpath: &str, val: &str) -> Result<(), std::io::Error> {
panic!("not implemented yet");
}

pub fn is_proc_handle(file: &File) -> Result<(), std::io::Error> {
panic!("not implemented yet");
pub fn is_proc_handle(file: &File) -> Result<(), std::io::Error> {
loop {
match statfs::fstatfs(file.as_fd()) {
Ok(stat) if stat.filesystem_type() == statfs::PROC_SUPER_MAGIC => break,
Ok(_) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other, format!("file {} is not on procfs", file.as_raw_fd())
));
},
Err(Errno::EINTR) => continue,
Err(err) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("fstatfs failed: {}", err)))
}
}
}
Ok(())
}

pub fn read_con_fd(file: &mut File) -> Result<String, std::io::Error> {
Expand Down

0 comments on commit 9c31834

Please sign in to comment.