Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Mar 4, 2024
1 parent 07822d6 commit d990b28
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const ROOT: &str = "/proc";

static KERNEL: Lazy<Option<String>> = Lazy::new(|| {
std::fs::read_to_string("/proc/sys/kernel/osreleas")
.and_then(|s| Ok(s.trim().to_owned()))
.and_then(|s| {
println!("KERNEL: {}",s);
Ok(s.trim().to_owned())})
.ok()
});

Expand All @@ -29,20 +31,21 @@ pub(crate) fn hi() {
fn get_all_processes() -> Vec<Process> {
// procfs::process::all_processes().unwrap();

let root = rustix::fs::openat(
let root = Path::new("/proc");
let dir = rustix::fs::openat(
rustix::fs::CWD,
Path::new(ROOT),
root,
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC,
Mode::empty(),
)
.unwrap();
let dir = rustix::fs::Dir::read_from(root).unwrap();
let dir = rustix::fs::Dir::read_from(dir).unwrap();

let mut processes: Vec<Process> = vec![];
for entry in dir {
if let Ok(e) = entry {
if let Ok(pid) = i32::from_str(&e.file_name().to_string_lossy()) {
let proc_root = PathBuf::from(ROOT).join(pid.to_string());
let proc_root = PathBuf::from(root).join(pid.to_string());

// for 2.6.39 <= kernel < 3.6 fstat doesn't support O_PATH see https://github.com/eminence/procfs/issues/265
let flags = match &*KERNEL {
Expand Down

0 comments on commit d990b28

Please sign in to comment.