Skip to content

Commit

Permalink
xattr
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroyuki Moriya <[email protected]>
  • Loading branch information
Gekko0114 committed Jun 29, 2024
1 parent 8ed6508 commit e6025be
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 75 deletions.
122 changes: 122 additions & 0 deletions experiment/selinux/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions experiment/selinux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ keywords = ["youki", "container", "selinux"]

[dependencies]
nix = { version = "0.29.0", features = ["process", "fs"] }
rustix = { version = "0.38.34", features = ["fs"] }
tempfile = "3.10.1"
thiserror = "1.0.61"
2 changes: 1 addition & 1 deletion experiment/selinux/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod selinux;
pub mod xattr;
pub mod xattrs;
18 changes: 9 additions & 9 deletions experiment/selinux/src/selinux.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::xattr::*;
use crate::xattrs::*;
use nix::unistd::gettid;
use nix::sys::statfs;
use nix::errno::Errno;
Expand Down Expand Up @@ -75,10 +75,10 @@ impl SELinux {
}

loop {
match set_xattr(fpath, XATTR_NAME_SELINUX, label.as_bytes(), 0) {
match set_xattr(fpath, XATTR_NAME_SELINUX, label.as_bytes()) {
Ok(_) => break,
// TODO: This line will be fixed after implementing set_xattr.
Err(EINTR) => continue,
// When a system call is interrupted by a signal, it needs to be retried.
Err(XattrError::EINTR(_)) => continue,
Err(e) => {
return Err(SELinuxError::SetFileLabel(
format!("set_xattr failed: {}", e),
Expand All @@ -98,10 +98,10 @@ impl SELinux {
}

loop {
match lset_xattr(fpath, XATTR_NAME_SELINUX, label.as_bytes(), 0) {
match lset_xattr(fpath, XATTR_NAME_SELINUX, label.as_bytes()) {
Ok(_) => break,
// TODO: This line will be fixed after implementing lset_xattr.
Err(EINTR) => continue,
// When a system call is interrupted by a signal, it needs to be retried.
Err(XattrError::EINTR(_)) => continue,
Err(e) => {
return Err(SELinuxError::LSetFileLabel(format!("lset_xattr failed: {}", e)));
}
Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
use crate::selinux::*;
use std::fs::{self, File};
use std::path::Path;
use std::io::Write;
use std::io::Write;

fn create_temp_file(content: &[u8], file_name: &str) {
let path = Path::new(file_name);
Expand Down Expand Up @@ -465,5 +465,5 @@ mod tests {
assert!(result.is_err(), "Expected Err, but got Ok");
}
}
}
}
}
65 changes: 0 additions & 65 deletions experiment/selinux/src/xattr/xattr.rs

This file was deleted.

File renamed without changes.
Loading

0 comments on commit e6025be

Please sign in to comment.