Check file_table in PID directory before access

This commit is contained in:
Marsman1996
2025-06-22 17:21:14 +08:00
committed by Ruihan Li
parent 1c56fbc871
commit 826f56aeed
2 changed files with 8 additions and 7 deletions

View File

@ -27,7 +27,7 @@ impl FdDirOps {
.parent(parent) .parent(parent)
.build() .build()
.unwrap(); .unwrap();
// Guard against the race condition when procfs is being accessed for an exiting process, // This is for an exiting process that has not yet been reaped by its parent,
// whose file table may have already been released. // whose file table may have already been released.
if let Some(file_table_ref) = file_table.lock().as_ref() { if let Some(file_table_ref) = file_table.lock().as_ref() {
file_table_ref file_table_ref

View File

@ -36,12 +36,13 @@ impl PidDirOps {
.volatile() .volatile()
.build() .build()
.unwrap(); .unwrap();
file_table // This is for an exiting process that has not yet been reaped by its parent,
.lock() // whose file table may have already been released.
.as_ref() if let Some(file_table_ref) = file_table.lock().as_ref() {
.unwrap() file_table_ref
.read() .read()
.register_observer(Arc::downgrade(&pid_inode) as _); .register_observer(Arc::downgrade(&pid_inode) as _);
}
pid_inode pid_inode
} }