Skip to content

Commit

Permalink
Fix calling proc_self_status() more than once. (#995)
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 authored Jan 16, 2024
1 parent 916887b commit 85eea13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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,
fstat, fstatfs, major, openat, renameat, seek, FileType, FsWord, Mode, OFlags, RawDir,
SeekFrom, Stat, CWD, PROC_SUPER_MAGIC,
};
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 85eea13

Please sign in to comment.