Skip to content

Commit 31b0910

Browse files
authored
Merge pull request #184 from sunfishcode/with-root
Re-introduce `all_processes_with_root`.
2 parents 8871f0a + 37c44c6 commit 31b0910

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/process/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,12 +1453,19 @@ impl std::iter::Iterator for TasksIter {
14531453
///
14541454
/// If a process can't be constructed for some reason, it won't be returned in the iterator.
14551455
pub fn all_processes() -> ProcResult<ProcessesIter> {
1456-
let root = PathBuf::from("/proc");
1456+
all_processes_with_root("/proc")
1457+
}
1458+
1459+
/// Return a list of all processes based on a specified `/proc` path
1460+
///
1461+
/// If a process can't be constructed for some reason, it won't be returned in the list.
1462+
pub fn all_processes_with_root(root: impl AsRef<Path>) -> ProcResult<ProcessesIter> {
1463+
let root = root.as_ref();
14571464
let dir = wrap_io_error!(
14581465
root,
14591466
rustix::fs::openat(
14601467
&rustix::fs::cwd(),
1461-
&root,
1468+
root,
14621469
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC,
14631470
Mode::empty()
14641471
)

0 commit comments

Comments
 (0)