Skip to content

Commit

Permalink
fix(symlink): fix /proc/self/exe readlink return len
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenRuiwei committed Aug 22, 2024
1 parent ffc577b commit 682dbe9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
24 changes: 0 additions & 24 deletions kernel/src/task/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,30 +691,6 @@ impl Task {
}
}

fn resolve_dentry(&self, dentry: Arc<dyn Dentry>) -> SysResult<Arc<dyn Dentry>> {
const MAX_RESOLVE_LINK_DEPTH: usize = 40;
let mut dentry_it = dentry;
for _ in 0..MAX_RESOLVE_LINK_DEPTH {
if dentry_it.is_negetive() {
return Ok(dentry_it);
}
match dentry_it.inode()?.itype() {
InodeType::SymLink => {
let path = block_on(async { dentry_it.open()?.readlink_string().await })?;
let path = if is_absolute_path(&path) {
Path::new(sys_root_dentry(), sys_root_dentry(), &path)
} else {
Path::new(sys_root_dentry(), dentry_it.parent().unwrap(), &path)
};
let new_dentry = path.walk(OpenFlags::empty())?;
dentry_it = new_dentry;
}
_ => return Ok(dentry_it),
}
}
Err(SysError::ELOOP)
}

/// Given a path, absolute or relative, will find.
pub fn resolve_path(&self, path: &str) -> SysResult<Arc<dyn Dentry>> {
let dentry = self.at_helper(AtFd::FdCwd, path, OpenFlags::empty())?;
Expand Down
2 changes: 1 addition & 1 deletion modules/vfs/src/procfs/self_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ impl File for ExeFile {
}
buf[0..exe.len()].copy_from_slice(exe.as_bytes());
buf[exe.len()] = '\0' as u8;
Ok(exe.len() + 1)
Ok(exe.len())
}
}

0 comments on commit 682dbe9

Please sign in to comment.