Skip to content

Commit

Permalink
Fix calling proc_self_status() more than once.
Browse files Browse the repository at this point in the history
Fix `proc_self_status()` to reset the directory cursor before iterating
through the directory entries when searching for bind mounts. This fixes
a failure when called more than once, due to the cursor being left at
the end.

Fixes #994.
  • Loading branch information
sunfishcode committed Jan 16, 2024
1 parent 916887b commit 01e567e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd};
use crate::ffi::CStr;
use crate::fs::{
fstat, fstatfs, major, openat, renameat, FileType, FsWord, Mode, OFlags, RawDir, Stat, CWD,
PROC_SUPER_MAGIC,
PROC_SUPER_MAGIC, SeekFrom, seek
};
use crate::io;
use crate::path::DecInt;
Expand Down Expand Up @@ -488,6 +488,9 @@ fn open_and_check_file(
let mut found_file = false;
let mut found_dot = false;

// Position the directory iteration at the start.
seek(dir, SeekFrom::Start(0))?;

let mut buf = [MaybeUninit::uninit(); 2048];
let mut iter = RawDir::new(dir, &mut buf);
while let Some(entry) = iter.next() {
Expand Down
8 changes: 8 additions & 0 deletions tests/procfs/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ fn test_proc_self() {
let fd = rustix::procfs::proc_self_fd().unwrap();
assert_ne!(fd.as_raw_fd(), 0);
}

#[test]
fn test_status_twice() {
let fd = rustix::procfs::proc_self_status().unwrap();
drop(fd);
let fd = rustix::procfs::proc_self_status().unwrap();
drop(fd);
}

0 comments on commit 01e567e

Please sign in to comment.