Skip to content

Commit 85eea13

Browse files
authored
Fix calling proc_self_status() more than once. (#995)
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.
1 parent 916887b commit 85eea13

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/procfs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
use crate::fd::{AsFd, BorrowedFd, OwnedFd};
2222
use crate::ffi::CStr;
2323
use crate::fs::{
24-
fstat, fstatfs, major, openat, renameat, FileType, FsWord, Mode, OFlags, RawDir, Stat, CWD,
25-
PROC_SUPER_MAGIC,
24+
fstat, fstatfs, major, openat, renameat, seek, FileType, FsWord, Mode, OFlags, RawDir,
25+
SeekFrom, Stat, CWD, PROC_SUPER_MAGIC,
2626
};
2727
use crate::io;
2828
use crate::path::DecInt;
@@ -488,6 +488,9 @@ fn open_and_check_file(
488488
let mut found_file = false;
489489
let mut found_dot = false;
490490

491+
// Position the directory iteration at the start.
492+
seek(dir, SeekFrom::Start(0))?;
493+
491494
let mut buf = [MaybeUninit::uninit(); 2048];
492495
let mut iter = RawDir::new(dir, &mut buf);
493496
while let Some(entry) = iter.next() {

tests/procfs/basic.rs

+8
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ fn test_proc_self() {
66
let fd = rustix::procfs::proc_self_fd().unwrap();
77
assert_ne!(fd.as_raw_fd(), 0);
88
}
9+
10+
#[test]
11+
fn test_status_twice() {
12+
let fd = rustix::procfs::proc_self_status().unwrap();
13+
drop(fd);
14+
let fd = rustix::procfs::proc_self_status().unwrap();
15+
drop(fd);
16+
}

0 commit comments

Comments
 (0)