Skip to content

Commit e70f7f9

Browse files
Fix thread parsing, previously was failing to use right dir
1 parent 6e32299 commit e70f7f9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/procrs/pid/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl Ord for Pid {
146146
/// will not be yielded. An atomic view of processes on the system seems
147147
/// non-trivial.
148148
pub struct PidIter {
149+
dir: String,
149150
dir_iter: ReadDir,
150151
query: PidQuery,
151152
}
@@ -159,14 +160,16 @@ impl PidIter {
159160
/// Create a new iterator over all processes in /proc, but only yield
160161
/// processes that match the given query.
161162
pub fn new_query(query: PidQuery) -> Result<Self, ProcError> {
162-
let proc_dir = Path::new("/proc");
163+
let dir_name = "/proc".to_owned();
164+
let proc_dir = Path::new(&dir_name);
163165
let dir_iter = try!(
164166
fs::read_dir(proc_dir)
165167
.map_err(|e|
166168
ProcError::new(ProcOper::Opening, ProcFile::ProcDir, Some(e), Some("PidIter"))
167169
)
168170
);
169171
Ok(PidIter {
172+
dir: dir_name.clone(),
170173
dir_iter: dir_iter,
171174
query: query,
172175
})
@@ -183,14 +186,15 @@ impl PidIter {
183186
)
184187
);
185188
Ok(PidIter {
189+
dir: dir_name.clone(),
186190
dir_iter: dir_iter,
187191
query: query
188192
})
189193
}
190194

191195
/// Given a DirEntry, try to create a Pid struct, and only return if
192196
/// it matches the query, and is complete.
193-
fn proc_dir_filter(entry_opt: Result<DirEntry, io::Error>, query: &PidQuery)
197+
fn proc_dir_filter(entry_opt: Result<DirEntry, io::Error>, query: &PidQuery, dir_name: &str)
194198
-> Option<Result<Pid, ProcError>> {
195199
let file = entry_opt
196200
.map_err(|e|
@@ -211,7 +215,7 @@ impl PidIter {
211215
// If an error is not hard (error opening or reading file),
212216
// do not error as it may be a now-dead process.
213217
// If a parsing error occurs, then do return an error.
214-
let prc = match Pid::new(pid) {
218+
let prc = match Pid::new_dir(Path::new(&dir_name), pid) {
215219
Ok(prc) => prc,
216220
Err(e) => {
217221
if e.is_hard() {
@@ -221,7 +225,7 @@ impl PidIter {
221225
}
222226
}
223227
};
224-
match prc.query(query) {
228+
match prc.query(&query) {
225229
true => Some(Ok(prc)),
226230
false => None
227231
}
@@ -236,7 +240,7 @@ impl Iterator for PidIter {
236240

237241
fn next(&mut self) -> Option<Self::Item> {
238242
for entry in self.dir_iter.by_ref() {
239-
match Self::proc_dir_filter(entry, &self.query) {
243+
match Self::proc_dir_filter(entry, &self.query, &self.dir) {
240244
some @ Some(_) => return some,
241245
None => continue
242246
}

0 commit comments

Comments
 (0)